VBA Loops Using Header Names

benntw

Board Regular
Joined
Feb 17, 2014
Messages
222
Office Version
  1. 365
Platform
  1. Windows
Currently I have a code that loops between two sheets using a unique value in column to see if there is a new value to add to the second sheet. Here is a sample of the code I am using below.

i = 2 'First Row Of Data On RS_Temp Sheet

Do Until Cells(i, 15).Value = ""
WoNum = Cells(i, 1).Value
NotiNum = Cells(i, 2).Value

KeepSearching = True
RowNum = 4 'First Row Of Data On Available In R Systems Sheet

RS_Avail.Activate

Do Until KeepSearching = False

If Cells(RowNum, 15).Value = ScopeNum Then
Cells(RowNum, 1).Value = WoNum
Cells(RowNum, 2).Value = NotiNum

KeepSearching = False

ElseIf Cells(RowNum, 15).Value = "" Then

Cells(RowNum, 1).Value = WoNum
Cells(RowNum, 2).Value = NotiNum

KeepSearching = False
Else
RowNum = RowNum + 1
End If
Loop
i = i + 1
RS_Temp.Activate
Loop

Can someone help me to use header names instead of calling out column numbers ? the RS_Temp is a data sheet and my RS_Avail sheet has a table that the data gets added to. I am trying to make it more dynamic in case any of the headers change in our system that I export from. Appreciate the help.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,215,503
Messages
6,125,179
Members
449,212
Latest member
kenmaldonado

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