VBA question to loop through data of a specific column

kidult7

New Member
Joined
Jan 11, 2021
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,
I am very new to VBA , basically this is what I am trying to achieve:

I am trying to locate and loop through the data with a sepefic month.
Now with the find function, i can locate the column with the for the month header. How can I find the "real range" I need from the next row onwards till the last row.
For example , with below, current find.address function will be at A3, the column I will need to look for will be A4 ( A3+1) till the last column of A with data.

any input will be appreciated. Thanks


Sub test()

Dim locatem As Range
Dim Frequency As Range
Dim currentmonth1 As String
Set ws = Worksheets("Current KIs")

currentmonth1 = Sheets("Instruction").Range("B6").Value
With ws.Range("3:3")
Set locatem = .Find(currentmonth1, LookIn:=xlValues)

End With



End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi & welcome to MrExcel.
How about
VBA Code:
With Ws.Range("3:3")
   Set locatem = .Find(currentmonth1, LookIn:=xlValues)
End With
If Not locatem Is Nothing Then
   Ws.Range(locatem.Offset(1), Ws.Cells(Rows.Count, locatem.Column).End(xlUp)).Copy
End If
 
Upvote 0
Solution
thanks for your respond, Perhaps below will be a better demonstration.
Basically what I need is loop through the specific column based on "current month"

I have set the current month to be dynamic:
so a condition need to set for Y/N value based on the column of the month For example, if it's Nov, then they will loop though the Nov 2020 column to determine the value underneath it till last row

should I set up the loop through range as locatem.Offset(1), Ws.Cells(Rows.Count, locatem.Column).End(xlUp))? or there should be other smarter way?

Thank you so much in advance



Nov 2020Dec 2020Jan 2021Y/N
RGR
YGG
GGY
GGG
GGG
GGG
NARG
GGG
 
Upvote 0
What is the condition & what column should the Y or N go in?
 
Upvote 0
Condition will be based on the conditional formatting previously set on the table with the traffic light
basically I want to put "Y" if traffic light icon is ( non-green) , ie. RedTrafficLight or YellowTrafficLight. and "N" for GreenTrafficLight. on a particular column BE accordingly.


I haven't tried myself if this is workable solution yet, but i know the function for traffic lights are as following..
.Icon = xlIconGreenTrafficLight

Sorry in advance if I sound silly
 
Upvote 0
In that case I suggest you start a new thread, giving full details, as this has nothing to do with your original question.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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