Hi, I hope this is the right spot for an Excel VBA question.
I'm new to Excel macros/VBA (first one attempted). Due to my inexperience in this area I've been searching for a solution for about a week without success, and I'm not sure if I've even been searching for the right terms to find the solution.
I'm trying to set up a macro that will copy a range in a row if a condition is met in columns of my table, and paste if the item does not exist in my list on another sheet.
My table is set up with a reference number for each listed item; with the item's details in columns A through F. The reference number is in column C. From column G and in columns to the right the table uses a nested IF with VLOOKUP statement to see if the reference number existed for a specific date marking the cell with either a "No" or a "1" for yes (with the date heading each column).
Since the ending column (of the dates section) may change, and the number of date columns I need to check may change I figure I could use this to find the starting point for columns to check for "No" or "1"
and just change the lastCol variable to move backward (to the left) from the starting column.
I think I can use the following to pull the range, find the next empty cell on my list and paste,
but I'm not sure if this is how I should end the statement if I need to continue to another column (to the left), or what I need to use to check the list to see if a reference number exists before the item is pasted.
In case it matters the mentioned variables have been declared as Long.
Does there need to be another If within my current loop that checks the list for the reference number? Would it be better to initiate the check where the loop that finds next empty cell on the list is; maybe with an If-Then-Else?
Please let me know if I am heading in the right direction.
Thanks in advance for any insight and/or knowledge dropped.
Jessi![[smile] [smile] [smile]](/data/assets/smilies/smile.gif)
I'm new to Excel macros/VBA (first one attempted). Due to my inexperience in this area I've been searching for a solution for about a week without success, and I'm not sure if I've even been searching for the right terms to find the solution.
I'm trying to set up a macro that will copy a range in a row if a condition is met in columns of my table, and paste if the item does not exist in my list on another sheet.
My table is set up with a reference number for each listed item; with the item's details in columns A through F. The reference number is in column C. From column G and in columns to the right the table uses a nested IF with VLOOKUP statement to see if the reference number existed for a specific date marking the cell with either a "No" or a "1" for yes (with the date heading each column).
Since the ending column (of the dates section) may change, and the number of date columns I need to check may change I figure I could use this to find the starting point for columns to check for "No" or "1"
Code:
lastCol = Range("F2").End(xlToRight).Column
Code:
lastCol = lastCol - 1
I think I can use the following to pull the range, find the next empty cell on my list and paste,
Code:
Do
'loop to pull data from Reference sheet
If ActiveCell.Offset(1, 0).Select = 1 Then
currRow = Range(ActiveCell).Row
Range(Cells(currRow, 2), Cells(currRow, 5)).Select
Selection.Copy
Sheets("List").Select
'loop that finds next empty cell on list
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Range (ActiveCell)
ActiveSheet.Paste
Sheets("Reference").Select
End If
Loop Until IsEmpty(ActiveCell) = True
In case it matters the mentioned variables have been declared as Long.
Does there need to be another If within my current loop that checks the list for the reference number? Would it be better to initiate the check where the loop that finds next empty cell on the list is; maybe with an If-Then-Else?
Please let me know if I am heading in the right direction.
Thanks in advance for any insight and/or knowledge dropped.
Jessi
![[smile] [smile] [smile]](/data/assets/smilies/smile.gif)