Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 199
Default Excel macro - VBA code query



I have an Excel Spreadsheet with rows of data in several categories.
Each category is separated by two blank rows. In column G, in the blank
cell immediately above each category, I write the category heading - a
process I have already automated using the macro Copy_Title.

To save having to manually run down column G and run Copy_Title in the
appropriate cells, I am now trying to write another macro which will
automate this task. However, my efforts have not achieved success so
far:


Sub Copy_Title_Auto()

Range("G2").Select

Dim LastRow As Long
Dim x As Long
Dim y As Long
y = ActiveCell.Column
LastRow = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
Application.ScreenUpdating = False
For x = LastRow To 2 Step -1
If Cells(x, y).Value = "" And Cells(x - 1, y).Value = "" Then
With Cells(x, y)
Call Copy_Title
End With
End If
Next x
Application.ScreenUpdating = True

End Sub


Can anyone help please?

Many thanks.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,182
Default Excel macro - VBA code query

Call Copy_Title

Where's the code for this?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,872
Default Excel macro - VBA code query

Hi,

Am Sun, 27 Mar 2016 10:09:07 +0100 schrieb Victor Delta:

Thanks. So perhaps that's where I was going wrong...? What I tried to
write was a macro that would go up column G, calling the Copy_Title
macro every time it got to a cell where the cell and the one above were
blank. (This is exactly what I do manually at present!)


you don't have to copy. You can refer correctly to your Author. Modify
in the code "your title" to the cell you wanted to copy:

Sub Test()
Dim LastRow As Long, i As Long

LastRow = Cells(Rows.Count, 7).End(xlUp).Row
For i = LastRow To 2 Step -1
If IsEmpty(Cells(i, 7)) And IsEmpty(Cells(i - 1, 7)) Then
Cells(i, 7) = "your title"
End If
Next
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
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
Refresh an Access Query using VBA code in Excel Peter G[_2_] Excel Programming 6 October 28th 09 03:18 PM
VB Code or Excel macro to run Query/Import on Access file Harry[_8_] Excel Programming 13 February 22nd 05 07:27 PM
VB macro code for SQL Query Dan[_39_] Excel Programming 5 July 19th 04 02:56 PM
Excel Query - Code problem Reney Langlois Excel Programming 3 June 15th 04 01:03 PM
Code to run an Access query from Excel Kelly[_7_] Excel Programming 3 January 17th 04 04:12 PM


All times are GMT +1. The time now is 07:20 AM.

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"