Code to auto fill down using Macro

hbuehanx

New Member
Joined
Oct 6, 2017
Messages
2
I extracted data from another database. I want to make this data in pivot table formatting, which means fill Country and Product Column in every row so I can do analytics by country or by product type. There are 15000 rows. How can I do it using Macro?

[TABLE="width: 500, align: left"]
<tbody>[TR]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]Country[/TD]
[TD]Product[/TD]
[TD]Product Type[/TD]
[/TR]
[TR]
[TD]QATAR[/TD]
[TD]Generators[/TD]
[TD]Type 1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Leads[/TD]
[TD]Type 1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 4[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Other[/TD]
[TD]Type 1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 3[/TD]
[/TR]
[TR]
[TD]BRAZIL[/TD]
[TD]Generators[/TD]
[TD]Type 1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Leads[/TD]
[TD]Type 1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Other [/TD]
[TD]Type 1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Type 3[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Re: How to write code to auto fill down using Macro

Based on how you depicted your worksheet design, try this:

Code:
Sub Test1()
Application.screenupdating = False
Dim LastRow As Long
LastRow = Cells(Rows.Count, 4).End(xlUp).Row
On Error Resume Next
With Range(Cells(2, 2), Cells(LastRow, 3))
.SpecialCells(4).FormulaR1C1 = "=R[-1]C"
.Value = .Value
End With
Err.Clear
Application.screenupdating = True
End Sub
 
Upvote 0
Re: How to write code to auto fill down using Macro

I am hoping some one can help me I am looking for some code to FillDown a selection of non consecutive cells. I recorded a basic macro below.

This is only a small sample of number of rows that I need to fill down.
Range("A22:D25").Select
Selection.FillDown
The next range skips 2 rows then continues to the next range
Range("A28:D31").Select
Selection.FillDown
This needs to continue in the pattern until the final range or stop if any of the copy down cells is blank. Final range would be.
[TABLE="width: 162"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Range("A3436:D3439").Select[/TD]
[/TR]
[TR]
[TD]Selection.FillDown[/TD]
[/TR]
</tbody>[/TABLE]



The column to the left of the cells mention in the macros have detail of hours worked start time etc when filtering on any of the other columns the persons name does not appear. Thats why I need to fill down spanning the four rows.

Many thanks for any help given.
 
Upvote 0
Re: How to write code to auto fill down using Macro

Deleted as didn't realise someone had hijacked the thread.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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