Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Macros in Excel 2003

I want to create a macro to perform the same task but I need it to
accommodate changes in data from spreadsheet to spreadsheet. For example,
say I have a spreadsheet that has data in the first 20 rows of column A. I
make a macro to find the first empty cell in column A which, in this case, is
A21 and then highlight all the rows above it. So rows 1 through 20 will be
highlighted. But let's say the next spreadsheet I run the macro in has data
in the first 50 rows of column A. Because I made the macro in the first
sheet the macro will find the first empty cell at A51 (which is right) but
then it highlights rows 1-20 just like in the first one. Surely, there's a
way to make a macro virtual, no? So no matter how many rows have data the
macro will find the first empty cell, whatever that is, and then highlight
all the rows above that. How can this be done?


  #2   Report Post  
Posted to microsoft.public.excel.programming
PA PA is offline
external usenet poster
 
Posts: 101
Default Macros in Excel 2003

this code will select row 1 to the row of the last used cell in column A

Range(Cells(1, 1), Cells(Cells(Columns(1).Rows.Count, 1).End(xlUp).Row,
1)).EntireRow.Select

pa

"Bishop" wrote:

I want to create a macro to perform the same task but I need it to
accommodate changes in data from spreadsheet to spreadsheet. For example,
say I have a spreadsheet that has data in the first 20 rows of column A. I
make a macro to find the first empty cell in column A which, in this case, is
A21 and then highlight all the rows above it. So rows 1 through 20 will be
highlighted. But let's say the next spreadsheet I run the macro in has data
in the first 50 rows of column A. Because I made the macro in the first
sheet the macro will find the first empty cell at A51 (which is right) but
then it highlights rows 1-20 just like in the first one. Surely, there's a
way to make a macro virtual, no? So no matter how many rows have data the
macro will find the first empty cell, whatever that is, and then highlight
all the rows above that. How can this be done?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Macros in Excel 2003

I copied this in exactly as it is here and it returned a syntax error. I'm
including a copy of my whole macro if that'll help.

Sub RepeatRepConsolidation()
'
' RepeatRepConsolidation Macro
' Macro recorded 3/3/2009 by bminter
'
' Keyboard Shortcut: Ctrl+k
'
Cells.Select
Selection.Copy
Sheets("Workspace").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.ClearFormats
Rows("1:1").Select
Selection.Cut
Sheets("Repeats").Select
ActiveSheet.Paste
Sheets("Workspace").Select
Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("P1") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Sheets("Repeats").Select
Selection.Cut
Sheets("Workspace").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Rows("2:2").Select
ActiveWindow.FreezePanes = True
Range("B:O,R:AA").Select
Selection.Delete Shift:=xlToLeft
Columns("A:C").Select
Selection.Copy
Sheets("Repeats").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A1:C5000").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Range(Cells(1, 1), Cells(Cells(Columns(1).Rows.Count, 1).End(xlUp).Row,
1)).EntireRow.Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End Sub

"PA" wrote:

this code will select row 1 to the row of the last used cell in column A

Range(Cells(1, 1), Cells(Cells(Columns(1).Rows.Count, 1).End(xlUp).Row,
1)).EntireRow.Select

pa

"Bishop" wrote:

I want to create a macro to perform the same task but I need it to
accommodate changes in data from spreadsheet to spreadsheet. For example,
say I have a spreadsheet that has data in the first 20 rows of column A. I
make a macro to find the first empty cell in column A which, in this case, is
A21 and then highlight all the rows above it. So rows 1 through 20 will be
highlighted. But let's say the next spreadsheet I run the macro in has data
in the first 50 rows of column A. Because I made the macro in the first
sheet the macro will find the first empty cell at A51 (which is right) but
then it highlights rows 1-20 just like in the first one. Surely, there's a
way to make a macro virtual, no? So no matter how many rows have data the
macro will find the first empty cell, whatever that is, and then highlight
all the rows above that. How can this be done?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Macros in Excel 2003

What does "highlighted" mean?

Selected or colored?

Sub hilight()
Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Select
Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Interior.ColorIndex = 6
End Sub

You choose which line you want to keep.


Gord Dibben MS Excel MVP

On Tue, 3 Mar 2009 12:58:03 -0800, Bishop
wrote:

I want to create a macro to perform the same task but I need it to
accommodate changes in data from spreadsheet to spreadsheet. For example,
say I have a spreadsheet that has data in the first 20 rows of column A. I
make a macro to find the first empty cell in column A which, in this case, is
A21 and then highlight all the rows above it. So rows 1 through 20 will be
highlighted. But let's say the next spreadsheet I run the macro in has data
in the first 50 rows of column A. Because I made the macro in the first
sheet the macro will find the first empty cell at A51 (which is right) but
then it highlights rows 1-20 just like in the first one. Surely, there's a
way to make a macro virtual, no? So no matter how many rows have data the
macro will find the first empty cell, whatever that is, and then highlight
all the rows above that. How can this be done?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Macros in Excel 2003

"Selected" is what I meant, yes. And thank you for the response. This works
great. Incidentally, I scoured the help files for this information but came
up with nothing. Is this something that's not in the help files or did it
simply evade me? One more question. I have a situation where I need to
consolidate a specific worksheet in multiple workbooks into one worksheet.
I'm looking over the consolidate help files and there doesn't seem to be a
way to do it. I did, however, see that you guys offer a Consolidation
Assistant for $50. Is that my only option for my particular need?

"Gord Dibben" wrote:

What does "highlighted" mean?

Selected or colored?

Sub hilight()
Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Select
Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Interior.ColorIndex = 6
End Sub

You choose which line you want to keep.


Gord Dibben MS Excel MVP

On Tue, 3 Mar 2009 12:58:03 -0800, Bishop
wrote:

I want to create a macro to perform the same task but I need it to
accommodate changes in data from spreadsheet to spreadsheet. For example,
say I have a spreadsheet that has data in the first 20 rows of column A. I
make a macro to find the first empty cell in column A which, in this case, is
A21 and then highlight all the rows above it. So rows 1 through 20 will be
highlighted. But let's say the next spreadsheet I run the macro in has data
in the first 50 rows of column A. Because I made the macro in the first
sheet the macro will find the first empty cell at A51 (which is right) but
then it highlights rows 1-20 just like in the first one. Surely, there's a
way to make a macro virtual, no? So no matter how many rows have data the
macro will find the first empty cell, whatever that is, and then highlight
all the rows above that. How can this be done?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macros in Excel 2003

I did, however, see that you guys offer a Consolidation
Assistant for $50.

In case you think people on this site, who offer assistance, work for
Microsoft or Google or any other company offering products for sale on this
site, you should know that they are all volunteers located in different parts
of the world who just don't mind sharing what they know with others at no
cost, up to a point. Some of the volunteers are also in the business of
selling their services, but not through this media.

"Bishop" wrote:

"Selected" is what I meant, yes. And thank you for the response. This works
great. Incidentally, I scoured the help files for this information but came
up with nothing. Is this something that's not in the help files or did it
simply evade me? One more question. I have a situation where I need to
consolidate a specific worksheet in multiple workbooks into one worksheet.
I'm looking over the consolidate help files and there doesn't seem to be a
way to do it. I did, however, see that you guys offer a Consolidation
Assistant for $50. Is that my only option for my particular need?

"Gord Dibben" wrote:

What does "highlighted" mean?

Selected or colored?

Sub hilight()
Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Select
Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Interior.ColorIndex = 6
End Sub

You choose which line you want to keep.


Gord Dibben MS Excel MVP

On Tue, 3 Mar 2009 12:58:03 -0800, Bishop
wrote:

I want to create a macro to perform the same task but I need it to
accommodate changes in data from spreadsheet to spreadsheet. For example,
say I have a spreadsheet that has data in the first 20 rows of column A. I
make a macro to find the first empty cell in column A which, in this case, is
A21 and then highlight all the rows above it. So rows 1 through 20 will be
highlighted. But let's say the next spreadsheet I run the macro in has data
in the first 50 rows of column A. Because I made the macro in the first
sheet the macro will find the first empty cell at A51 (which is right) but
then it highlights rows 1-20 just like in the first one. Surely, there's a
way to make a macro virtual, no? So no matter how many rows have data the
macro will find the first empty cell, whatever that is, and then highlight
all the rows above that. How can this be done?



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Macros in Excel 2003

I'm not one of the "you guys".

I'm simply a retired old gent who answers questions(and asks some) on these
Excel news groups.

Very rarely do one of "you guys" show up on these groups.

Microsoft sponsors these groups but have very little input.

Check out Ron de Bruin's site for methods of Copy/Paste/Merge for getting
data from multiple books to one book.

http://www.rondebruin.nl/tips.htm

Maybe this one?

http://www.rondebruin.nl/summary2.htm


Gord Dibben MS Excel MVP

On Tue, 3 Mar 2009 14:33:01 -0800, Bishop
wrote:

"Selected" is what I meant, yes. And thank you for the response. This works
great. Incidentally, I scoured the help files for this information but came
up with nothing. Is this something that's not in the help files or did it
simply evade me? One more question. I have a situation where I need to
consolidate a specific worksheet in multiple workbooks into one worksheet.
I'm looking over the consolidate help files and there doesn't seem to be a
way to do it. I did, however, see that you guys offer a Consolidation
Assistant for $50. Is that my only option for my particular need?

"Gord Dibben" wrote:

What does "highlighted" mean?

Selected or colored?

Sub hilight()
Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Select
Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Interior.ColorIndex = 6
End Sub

You choose which line you want to keep.


Gord Dibben MS Excel MVP

On Tue, 3 Mar 2009 12:58:03 -0800, Bishop
wrote:

I want to create a macro to perform the same task but I need it to
accommodate changes in data from spreadsheet to spreadsheet. For example,
say I have a spreadsheet that has data in the first 20 rows of column A. I
make a macro to find the first empty cell in column A which, in this case, is
A21 and then highlight all the rows above it. So rows 1 through 20 will be
highlighted. But let's say the next spreadsheet I run the macro in has data
in the first 50 rows of column A. Because I made the macro in the first
sheet the macro will find the first empty cell at A51 (which is right) but
then it highlights rows 1-20 just like in the first one. Surely, there's a
way to make a macro virtual, no? So no matter how many rows have data the
macro will find the first empty cell, whatever that is, and then highlight
all the rows above that. How can this be done?




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Macros in Excel 2003

Well, Gord, whoever you are I would like to say thank you for your
assistance. I took your advice and checked out Ron's instructions. I
"thought" I found what I was looking for but I can't seem to get it to work
right. Here's what I'm trying to do:

I have a folder called "Compilation Complete" on my C: drive. It has
several Excel Files in it. In each file (workbook) there is a sheet called
Rootcause. I'm trying to get all the data from each Rootcause sheet from all
the workbooks and compile in one single sheet. The code below simply creates
a destination sheet but there's no data there. Nothing. What am I doing
wrong?

Function RDB_Last(choice As Integer, rng As Range)
'The following function is used in the selection process from the source
'By Ron de Bruin, 5 May 2008
'A choice of 1 = last row.
'A choice of 2 = last column.
'A choice of 3 = last cell.
Dim lrw As Long
Dim lcol As Integer

Select Case choice

Case 1:
On Error Resume Next
RDB_Last = rng.Find(What:="*", _
after:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0

Case 2:
On Error Resume Next
RDB_Last = rng.Find(What:="*", _
after:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0

Case 3:
On Error Resume Next
lrw = rng.Find(What:="*", _
after:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0

On Error Resume Next
lcol = rng.Find(What:="*", _
after:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0

On Error Resume Next
RDB_Last = rng.Parent.Cells(lrw, lcol).Address(False, False)
If Err.Number 0 Then
RDB_Last = rng.Cells(1).Address(False, False)
Err.Clear
End If
On Error GoTo 0

End Select
End Function

Sub MergeAllWorkbooks()
'This program consolidates a specific worksheet from all workbooks
'in a folder. In this case I am consolidating all Rootcause worksheets
'from all PF workbooks for each individual center.

Dim FirstCell As String
Dim MyPath As String, FilesInPath As String
Dim MyFiles() As String
Dim SourceRcount As Long, FNum As Long
Dim mybook As Workbook, BaseWks As Worksheet
Dim sourceRange As Range, destrange As Range
Dim rnum As Long, CalcMode As Long


'This is the path to the folders where the workbooks are contained.
MyPath = "C:\Compilation Complete"

'Add a slash at the end of the path if needed.
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder, exit.
FilesInPath = Dir(MyPath & "*.xl*")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If

'Fill the myFiles array with the list of Excel files
'in the search folder.
FNum = 0
Do While FilesInPath < ""
FNum = FNum + 1
ReDim Preserve MyFiles(1 To FNum)
MyFiles(FNum) = FilesInPath
FilesInPath = Dir()
Loop

'Set various application properties.
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With

'Add a new workbook with one sheet.
Set BaseWks = Workbooks.Add(xlWBATWorksheet).Worksheets(1)
rnum = 1

'Loop through all files in the myFiles array.
If FNum 0 Then
For FNum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(MyPath & MyFiles(FNum))
On Error GoTo 0

If Not mybook Is Nothing Then
On Error Resume Next

'Change this range to accommodate the range in the worksheet.
With mybook.Worksheets(Rootcause)
FirstCell = "A2"
Set sourceRange = .Range(FirstCell & ":" & RDB_Last(1,
..Rows))
'Test if the row of the last cell is equal to or greater
than the row of the first cell.
If RDB_Last(1, .Cells) < .Range(FirstCell).Row Then
Set sourceRange = Nothing
End If
End With


If Err.Number 0 Then
Err.Clear
Set sourceRange = Nothing
Else
'If source range uses all columns then skip this file.
If sourceRange.Columns.Count = BaseWks.Columns.Count Then
Set sourceRange = Nothing
End If
End If
On Error GoTo 0

If Not sourceRange Is Nothing Then

SourceRcount = sourceRange.Rows.Count

If rnum + SourceRcount = BaseWks.Rows.Count Then
MsgBox "There are not enough rows in the target
worksheet."
BaseWks.Columns.AutoFit
mybook.Close savechanges:=False
GoTo ExitTheSub
Else

'Copy the file name in column A.
With sourceRange
BaseWks.Cells(rnum, "A"). _
Resize(.Rows.Count).Value = MyFiles(FNum)
End With

'Set the destination range.
Set destrange = BaseWks.Range("B" & rnum)

'Copy the values from the source range to the
destination range.
With sourceRange
Set destrange = destrange. _
Resize(.Rows.Count,
..Columns.Count)
End With
destrange.Value = sourceRange.Value

rnum = rnum + SourceRcount
End If
End If
mybook.Close savechanges:=False
End If

Next FNum
BaseWks.Columns.AutoFit
End If

ExitTheSub:
' Restore the application properties.
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalcMode
End With
End Sub



"Gord Dibben" wrote:

I'm not one of the "you guys".

I'm simply a retired old gent who answers questions(and asks some) on these
Excel news groups.

Very rarely do one of "you guys" show up on these groups.

Microsoft sponsors these groups but have very little input.

Check out Ron de Bruin's site for methods of Copy/Paste/Merge for getting
data from multiple books to one book.

http://www.rondebruin.nl/tips.htm

Maybe this one?

http://www.rondebruin.nl/summary2.htm


Gord Dibben MS Excel MVP

On Tue, 3 Mar 2009 14:33:01 -0800, Bishop
wrote:

"Selected" is what I meant, yes. And thank you for the response. This works
great. Incidentally, I scoured the help files for this information but came
up with nothing. Is this something that's not in the help files or did it
simply evade me? One more question. I have a situation where I need to
consolidate a specific worksheet in multiple workbooks into one worksheet.
I'm looking over the consolidate help files and there doesn't seem to be a
way to do it. I did, however, see that you guys offer a Consolidation
Assistant for $50. Is that my only option for my particular need?

"Gord Dibben" wrote:

What does "highlighted" mean?

Selected or colored?

Sub hilight()
Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Select
Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Interior.ColorIndex = 6
End Sub

You choose which line you want to keep.


Gord Dibben MS Excel MVP

On Tue, 3 Mar 2009 12:58:03 -0800, Bishop
wrote:

I want to create a macro to perform the same task but I need it to
accommodate changes in data from spreadsheet to spreadsheet. For example,
say I have a spreadsheet that has data in the first 20 rows of column A. I
make a macro to find the first empty cell in column A which, in this case, is
A21 and then highlight all the rows above it. So rows 1 through 20 will be
highlighted. But let's say the next spreadsheet I run the macro in has data
in the first 50 rows of column A. Because I made the macro in the first
sheet the macro will find the first empty cell at A51 (which is right) but
then it highlights rows 1-20 just like in the first one. Surely, there's a
way to make a macro virtual, no? So no matter how many rows have data the
macro will find the first empty cell, whatever that is, and then highlight
all the rows above that. How can this be done?





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
How do I get 2003 Macros and Toolbar Buttons form Excel 2003 to 20 Scott Sornberger New Users to Excel 2 March 19th 08 11:42 AM
need help macros excel 2003 kathepoo Excel Programming 1 June 22nd 07 11:28 AM
Macros Excel 2003 Tanya Excel Programming 1 September 20th 06 07:22 PM
Excel 2003 and Macros Kevin Murphy Excel Discussion (Misc queries) 0 June 21st 06 09:16 PM
Excel 2003 macros pspeed Excel Discussion (Misc queries) 4 December 15th 05 12:54 AM


All times are GMT +1. The time now is 08:59 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"