VB Question

earthsuiter

New Member
Joined
Jul 14, 2009
Messages
34
Good Afternoon,

I'm tring to figure out what the VB code I would need to do the following:

Look at all values in column B
If value = "break" then .RowHeight = 2.5

Thanks for your time.
Tim
 
I'm not clear what you want to do but maybe look at the Select Case statement
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Select Case option

Code:
Sub jhj()
Dim LR, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    Select Case Range("B" & i).Value
        Case Is = "break"
            Rows(i).RowHeight = 2.5
        Case Is = "space"
            Rows(i).RowHeight = 15
        Case Is = "header"
            Sheets("Coding").Range("A1:E1").Copy Range("B" & i)
    End Select
Next i
End Sub
 
Upvote 0
Awesome ...I'm pretty sure this is my last question.
How do you code it to look for the value '@' and insert x number of blanks rows down?
 
Upvote 0
Try

Code:
Sub jhj()
Dim LR, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    Select Case Range("B" & i).Value
        Case "break": Rows(i).RowHeight = 2.5
        Case "space": Rows(i).RowHeight = 15
        Case "header": Sheets("Coding").Range("A1:E1").Copy Range("B" & i)
        Case "@": Rows(i).Resize(3).Insert
    End Select
Next i
End Sub
 
Upvote 0
Hi Peter,

It works, but... Not sure.

Is there a way to tell the Macro, as soon as you see the '@' stop and put the remainder of data on A1 of page 2?
 
Upvote 0
Perhaps

Code:
Sub jhj()
Dim LR, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    Select Case Range("B" & i).Value
        Case "break": Rows(i).RowHeight = 2.5
        Case "space": Rows(i).RowHeight = 15
        Case "header": Sheets("Coding").Range("A1:E1").Copy Range("B" & i)
        Case "@": Rows(i & ":" & LR).Cut Destination:=Sheets("Sheet2").Range("A1"): Exit Sub
    End Select
Next i
End Sub
 
Last edited:
Upvote 0
Peter,

With the last change you made to the Macro, it is only formatting the data from A76 down. I still need the Macro to format everything on the page. Thanks again for all your help.

Case "@": Rows(i & ":" & LR).Cut Destination:=Sheets("Test Sheet").Range("A76"): Exit Sub
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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