Variable not set up right?

butch3

Board Regular
Joined
Feb 4, 2019
Messages
54
Hi all. I've created this simple code to help me move some data around. I'm trying to move data from Column C to Column D, E, F, etc when there is no text in a cell within Column B. See my code and example below.

Sub Test()​

Dim rownum As Long​
Dim rowtext As Long​
Dim colmnltr As Long​

For rownum = 2 To 950​

If IsEmpty(Range("B" & rownum)) Then​

Range("C" & rownum).Select​
Selection.Cut​
colmnltr = colmnltr + 1​
Range(Columns(colmnltr) & rowtext).Select​
ActiveSheet.Paste​
Else​

rowtext = rownum​
colmnltr = 3​

End If​

Next rownum​

End Sub

Initial Data:
NameRelationshipImmediate FamilyNOK 1NOK 2NOK 3
FName LNameFatherSon - First Last
Mother - XX
Father - XY
First LastBrotherMother - XX
Father - XY

<tbody>
</tbody>

After VBA formatting:
NameRelationshipImmediate FamilyNOK 1NOK 2NOK 3
FName LNameFatherSon - First LastMother - XXFather - XY
First LastBrotherMother - XXFather - XY

<tbody>
</tbody>
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
How about
Code:
Sub butch3()
   Dim rng As Range
   
   For Each rng In Range("B:B").SpecialCells(xlBlanks).Areas
      rng.Offset(-1, 2).Resize(1, rng.Count).Value = Application.Transpose(rng.Offset(, 1).Value)
      rng.Offset(, 1).Value = ""
     [COLOR=#ff0000] rng.EntireRow.Delete[/COLOR]
   Next rng
End Sub
If you don't want to delete the empty rows remove the line in red.
 
Upvote 0
That was incredibly efficient.

Is there any reason that my code didn't or wouldn't work? I guess I need to read more about the specialcells, areas, offset, resize, and transpose functions.
 
Upvote 0
To be honest I didn't actually look at your code.
But this wont work
Code:
Range(Columns(colmnltr) & rowtext).Select
as Range needs a letter for the column not a number.
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,772
Members
449,095
Latest member
m_smith_solihull

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