I just want headers above each category in a column

kadain

New Member
Joined
May 19, 2022
Messages
22
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
hi guys/gals
am just looking for a vba code that reads up a table column B, copys the first none blank value in its finds and pastes it to the next blank column then repeats
ive tried many different ways of trying it but no luck to the point it deletes everything but the headers it made

Screenshot 2022-05-19 151213.png

just so yous have an idea of how the data would look and what column the list goes on for ever so any range I would just go to max cell
all I really want is headers between each type of sub category
so if it was pasted bold and underlined that would be perfect
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
We cannot manipulate data in a picture. Please re upload same data using XL2BB. See my signature for instructions.
 
Upvote 0
We cannot manipulate data in a picture. Please re upload same data using XL2BB. See my signature for instructions.
VBA Test Book.xlsm
ABCDE
1Product CodeProduct Sub CategoryProduct DescriptionProduct SizePack Size
2
3123CiderKOPPARBERG MIXED TROPICAL FRUIT 4% 500ML NRB15x500ML B1
41223124CiderKOPPARBERG STRAWBERRY ANDLIME 4% 500ML NRB15x500ML B1
5131231CiderKOPPARBERG MIXED FRUIT 4%500ML NRB15x500ML B1
642414CiderMAGNERS IRISH CIDER 4.5% 568ML NRB12x568ML B1
7
8
9123123123Premium LagerBUDWEISER LAGER 4.5% 330ML NRB24x330ML B1
10
11
12412444Standard LagerBECKS BIER 4.8% 275ML24x275ML B1
1342442Standard LagerMILLER GENUINE DRAFT 4.7%330ML NRB24x NRB1
14
15
1634535Std Ale / IpaNEWCASTLE BROWN ALE 4.7%550ML NRB12x550ML B1
17
18
1935435World BeerCORONA EXTRA LAGER 4.5% 330ML NRB24x330ML B1
2022555World BeerPERONI NASTRO AZZURO 5.1%330ML NRB24x330ML B1
21
22
235235352Low Alcohol BeerHEINEKEN 0.0% NON ALCOHOLIC LAGER BEER 330ML NRB24x NRB1
24
25
261606WPre-Mixed DrinksSMIRNOFF ICE 4% 275ML24x NRB1
279629LPre-Mixed DrinksWKD BLUE 4%24x NRB1
Sheet1
 
Upvote 0
Here is a VBA code to make that happen
VBA Code:
Option Explicit

Sub ProdDesc()
    Dim lr As Long, i As Long
    Application.ScreenUpdating = False
    lr = Range("A" & Rows.Count).End(xlUp).Row
    For i = 3 To lr
        If Range("B" & i - 1) = "" Then
            Range("B" & i - 1) = Range("B" & i)
        End If
    Next i
    Application.ScreenUpdating = True
    MsgBox "complete"
End Sub
 
Upvote 0
Solution
We cannot manipulate data in a picture. Please re upload same data using XL2BB. See my signature for instructions.
Here is a VBA code to make that happen
VBA Code:
Option Explicit

Sub ProdDesc()
    Dim lr As Long, i As Long
    Application.ScreenUpdating = False
    lr = Range("A" & Rows.Count).End(xlUp).Row
    For i = 3 To lr
        If Range("B" & i - 1) = "" Then
            Range("B" & i - 1) = Range("B" & i)
        End If
    Next i
    Application.ScreenUpdating = True
    MsgBox "complete"
End Sub
Thank you so much, i dont think i would of been able to figure this out my self.
if youve got time could you run me threw the steps so i can understand the code a little better
it works wonders with the exsisting code ive wrote and ties in neatly
 
Upvote 0
VBA Code:
Option Explicit

Sub ProdDesc()
    Dim lr As Long, i As Long 'Define your variables as long integers
    Application.ScreenUpdating = False 'Set the screen to not flashing
    lr = Range("A" & Rows.Count).End(xlUp).Row 'Determine the last row in column A
    For i = 3 To lr 'set loop to move through rows number 3 to last row
        If Range("B" & i - 1) = "" Then 'if the range of data in the one row above the looped row is empty then the next line of code
            Range("B" & i - 1) = Range("B" & i) 'if the above line of code is true then make the row above the looped row the same as the looped row
        End If 'stop the if--then scenario
    Next i 'loop to the next row
    Application.ScreenUpdating = True 'activate the screen
    MsgBox "complete"
End Sub
 
Upvote 0
Hey @alansidman,

Colleague of *kadain here. Really appreciate your timely help. We were struggling with this for a couple of days and your code did the trick in a couple of minutes!

Where do we give 5 stars?

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,223,937
Messages
6,175,510
Members
452,650
Latest member
Tinfish

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