using Resize to define range for updating a COLUMN from userform

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
476
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have code that I regularly use to update a ROW source for amending data that is in a row (going across), but I cannot figure out how to do the same thing but from a column.

Code:
Private Sub cmdAdd1_Click()

Dim DynRng As Range, Inc_ID As String, r As Long
Set DynRng = Worksheets("Seatex Incident Log").Range("DynamicRange")

Inc_ID = txtIncidentID1

r = Application.WorksheetFunction.Match(Inc_ID, DynRng.Resize(, 1), 0)

DynRng.Cells(r, [COLOR=#000080][B]2[/B][/COLOR]).Value = Me.DTPicker3.Value
DynRng.Cells(r, [COLOR=#000080][B]4[/B][/COLOR]).Value = Me.cboPriority1.Value
DynRng.Cells(r, [COLOR=#000080][B]18[/B][/COLOR]).Value = Me.chkCAPA1.Value
DynRng.Cells(r, [COLOR=#000080][B]6[/B][/COLOR]).Value = Me.cboLocation1.Value
("Inc_ID" is located somewhere in column A)
Where: (r, 2), (r, 4), (r, 18), or (r, 6) are all cells located 2 columns over from "Inc_ID" , or 4 columns over, or 18 columns over... etc...

But... what if 'Inc_ID' is located somewhere in row 1 (in some column) and I want to go DOWN from that specific cell. How do i define my new range for going down rows instead of going across columns like the above code does? (sure hope that makes sense... thank you)
 
Your lookup range is wrong as it's only 1 column wide.
try
Code:
r = Application.WorksheetFunction.Match(namID, DynRng.Resize[COLOR=#000080][B](1), 0)[/B][/COLOR]
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Your lookup range is wrong as it's only 1 column wide.
try
Code:
r = Application.WorksheetFunction.Match(namID, DynRng.Resize[COLOR=#000080][B](1), 0)[/B][/COLOR]
YES! :) THank you so much, Fluff. That did the trick.
icon14.png
icon14.png
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top