![]() |
Macro code to check & copy columns
Hello! I need some help with a macro code. I'm a beginner who doesn't know quite how to do begin. I have records in rows in an Excel spread sheet, I need code that would check each record to see if data is present in column AB cell. If AB is NOT blank, I need it to check if column AA cell is blank. If it is blank, I need it to copy the data from column B cell to column AA cell...again only if column AB is not blank and AA is blank. Whew! Hope that made sense. Thanks in advance for all your help. -- mercedes ------------------------------------------------------------------------ mercedes's Profile: http://www.excelforum.com/member.php...o&userid=24979 View this thread: http://www.excelforum.com/showthread...hreadid=473634 |
Macro code to check & copy columns
This seems to work according to your description:
Sub CopyData() Dim lRow As Long Dim rng As Range Dim c As Range lRow = Cells(Rows.Count, "B").End(xlUp).Row Set rng = Range("B1:B" & lRow) For Each c In rng.Cells If c.Offset(, 26).Value < "" _ And c.Offset(, 25).Value = "" Then c.Offset(, 25).Value = c.Value End If Next c End Sub Mike F "mercedes" wrote in message ... Hello! I need some help with a macro code. I'm a beginner who doesn't know quite how to do begin. I have records in rows in an Excel spread sheet, I need code that would check each record to see if data is present in column AB cell. If AB is NOT blank, I need it to check if column AA cell is blank. If it is blank, I need it to copy the data from column B cell to column AA cell...again only if column AB is not blank and AA is blank. Whew! Hope that made sense. Thanks in advance for all your help. -- mercedes ------------------------------------------------------------------------ mercedes's Profile: http://www.excelforum.com/member.php...o&userid=24979 View this thread: http://www.excelforum.com/showthread...hreadid=473634 |
Macro code to check & copy columns
' This checks "AA" ="" (Empty) and "AB"<"" Not Empty
' when you click on a cell in the AA column Public Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Column = 27 Then If Cells(Target.row, "AA").Value = "" And Cells(Target.row, "AB") < "" Then Cells(Target.row, "AA") = Cells(Target.row, "B") MsgBox Str(Target.row) & ":" & Str(Target.Column) & " Nil" End If End If End Sub ' Hope this helps Mercedes ' Andrew "mercedes" wrote in message ... | | Hello! | I need some help with a macro code. I'm a beginner who doesn't know | quite how to do begin. I have records in rows in an Excel spread sheet, | I need code that would check each record to see if data is present in | column AB cell. If AB is NOT blank, I need it to check if column AA | cell is blank. If it is blank, I need it to copy the data from column B | cell to column AA cell...again only if column AB is not blank and AA is | blank. Whew! Hope that made sense. Thanks in advance for all your help. | | | -- | mercedes | ------------------------------------------------------------------------ | mercedes's Profile: http://www.excelforum.com/member.php...o&userid=24979 | View this thread: http://www.excelforum.com/showthread...hreadid=473634 | |
All times are GMT +1. The time now is 11:55 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com