Macro to Find the last row of a section and paste into that area?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I have a bit of a problem,

I have a sheet called Lists,

In this sheet I have lots of products
Column A is the SKU for each product,
Column B serves a dual propose, not only does it hold the product description but also the Category name
So if you can imagine all the products laid out in rows
Column B holds the Categories, and then below that are all the products for that Categorie.

fortunately the Categories are separated by at least one empty row.

So heres what i need,

A Macro to look at the product category name in sheet Control D4

Find that name in Sheet "Lists" column B and then find the first blank line in column A after it and select it

please help if you can

Thanks

Tony
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try this:
VBA Code:
Sub Test()
Dim WS1 As Worksheet, WS2 As Worksheet, M As Long, N As Long
Set WS1 = Sheets("Control")
Set WS2 = Sheets("List")
M = Application.WorksheetFunction.Match(WS1.Range("D4"), WS2.Range("B1", WS2.Range("B" & Rows.Count).End(xlUp)), 0)
If WS2.Range("A" & M).Value = "" Then
N = M
ElseIf WS2.Range("A" & M + 1).Value = "" Then
N = M + 1
Else
N = WS2.Range("A" & M).End(xlDown).Row + 1
End If
WS2.Activate
WS2.Range("A" & N).Select
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,731
Members
449,093
Latest member
Mnur

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