Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default Need macro to autofill when there are blank cells

I am pulling a standard report from SAP. I have inserted lines, which left
blank cells in column A. Column A is primary key for my pivot table.
Therefore, i need macro that will recognize any blank cells in column A then
autofill them using the first filled out cell above the blank cell.

I tried
For each cell in range ("a:a")
If cell.value="" then
cell.offset(-1,0).copy
cell.offset(1,0).paste
end if
next cell

but this did not work. any suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Need macro to autofill when there are blank cells

Hi Christy,

TryL

'=============
Public Sub Tester()
Dim SH As Worksheet
Dim rng As Range
Dim rng2 As Range

Set SH = ActiveSheet '<<==== CHANGE

With SH
Set rng = Intersect(.Columns("A"), .UsedRange)
End With

On Error Resume Next
Set rng2 = rng.SpecialCells(xlBlanks)
On Error GoTo 0

If Not rng2 Is Nothing Then
rng2.FormulaR1C1 = "=R[-1]C"
rng.Value = rng.Value
End If
End Sub
'<<=============

---
Regards,
Norman



"Christy" wrote in message
...
I am pulling a standard report from SAP. I have inserted lines, which left
blank cells in column A. Column A is primary key for my pivot table.
Therefore, i need macro that will recognize any blank cells in column A
then
autofill them using the first filled out cell above the blank cell.

I tried
For each cell in range ("a:a")
If cell.value="" then
cell.offset(-1,0).copy
cell.offset(1,0).paste
end if
next cell

but this did not work. any suggestions?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Need macro to autofill when there are blank cells

Sub Replaceblanks()
Dim rng as Range, rng1 as Range
set rng = Range(cells(1,1),cells(rows.count,2).End(xlup).off set(0,-1))
set rng1 = rng.specialcells(xlBlanks)
rng1.formulaR1C1 = "=R[-1]C"
rng.Formula = rng.Value
End sub

--
Regards,
Tom Ogilvy



"Christy" wrote:

I am pulling a standard report from SAP. I have inserted lines, which left
blank cells in column A. Column A is primary key for my pivot table.
Therefore, i need macro that will recognize any blank cells in column A then
autofill them using the first filled out cell above the blank cell.

I tried
For each cell in range ("a:a")
If cell.value="" then
cell.offset(-1,0).copy
cell.offset(1,0).paste
end if
next cell

but this did not work. any suggestions?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I can't autofill cells in a column if blank cells in between SJ Excel Worksheet Functions 1 May 4th 08 01:27 AM
Autofill: Need to autofill one week block, (5) weekday only into cells. dstock Excel Discussion (Misc queries) 1 June 17th 05 08:21 PM
Use Autofill in a macro to fill blank cells until next text - goldyjk Excel Programming 1 June 14th 05 06:40 PM
Autofill data in specific blank cells Mr. G. Excel Worksheet Functions 0 April 22nd 05 09:41 PM
Use Autofill in a macro to fill blank cells until next text - Bernie Deitrick Excel Programming 0 February 18th 05 06:45 PM


All times are GMT +1. The time now is 03:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"