ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need help with code for Excel Macro (https://www.excelbanter.com/excel-programming/333813-need-help-code-excel-macro.html)

mercedes[_2_]

Need help with code for Excel Macro
 

Hi!
Please help...
I'm trying to code a macro in Excel that has me stumped.
In column A, I have either a letter P or C in each row.
If it's C, I want all the data from columns H, I, J, and K to move to
columns R, S, T, and U within the row.
Any ideas would be greatly appreciated


--
mercedes
------------------------------------------------------------------------
mercedes's Profile: http://www.excelforum.com/member.php...o&userid=24979
View this thread: http://www.excelforum.com/showthread...hreadid=385101


Jim Thomlinson[_4_]

Need help with code for Excel Macro
 
Give this a try...

Sub MoveData()
Dim rngToCheck As Range
Dim rngToMove As Range
Dim wks As Worksheet

Set wks = ActiveSheet
Set rngToCheck = wks.Range("A65536").End(xlUp)

Do While rngToCheck.Row 1
If UCase(Trim(rngToCheck.Value)) = "C" Then
Set rngToMove = Range(rngToCheck.Offset(0, 7), _
rngToCheck.Offset(0, 10))
rngToMove.Copy rngToCheck.Offset(0, 17)
rngToMove.ClearContents
End If
Set rngToCheck = rngToCheck.Offset(-1, 0)
Loop
End Sub

--
HTH...

Jim Thomlinson


"mercedes" wrote:


Hi!
Please help...
I'm trying to code a macro in Excel that has me stumped.
In column A, I have either a letter P or C in each row.
If it's C, I want all the data from columns H, I, J, and K to move to
columns R, S, T, and U within the row.
Any ideas would be greatly appreciated


--
mercedes
------------------------------------------------------------------------
mercedes's Profile: http://www.excelforum.com/member.php...o&userid=24979
View this thread: http://www.excelforum.com/showthread...hreadid=385101



William Benson[_2_]

Need help with code for Excel Macro
 
Mercedes, I think this should work for you ... or use Jim's answer, but be
warned that if you have any formulas in H, I, J, or K, they will be changed
with the other approach. At least you will also see the benefits of multiple
approaches. Regards, Bill

Sub AdjustLocation()
Dim Cell As Range
For Each Cell In ActiveSheet.Cells(1).EntireColumn.Cells
If Len(Cell) = 0 Then
Exit For
Else
If Cell = "C" Then
With ActiveSheet
.Range("H" & Cell.Row, "K" & Cell.Row).Cut .Range("R" &
Cell.Row)
End With
End If
End If
Next Cell
End Sub


"mercedes" wrote in
message ...

Hi!
Please help...
I'm trying to code a macro in Excel that has me stumped.
In column A, I have either a letter P or C in each row.
If it's C, I want all the data from columns H, I, J, and K to move to
columns R, S, T, and U within the row.
Any ideas would be greatly appreciated


--
mercedes
------------------------------------------------------------------------
mercedes's Profile:
http://www.excelforum.com/member.php...o&userid=24979
View this thread: http://www.excelforum.com/showthread...hreadid=385101





All times are GMT +1. The time now is 12:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com