|
-
Jan 4th, 2005, 04:34 PM
#1
Thread Starter
New Member
I could use a hand with this one.
Ok I have code here that will move the text that is highlighted in yellow in any cell in row C from worksheet A to the same postion in worksheet B.
VB Code:
Dim aColor As Integer
Dim aCell As Range
Dim aWorksheet As Worksheet
Dim bWorksheet As Worksheet
Set aWorksheet = Worksheets("DATA")
Set bWorksheet = Worksheets("NegativeFMs")
r1 = 2
c1 = 1
a1 = 1
b1 = 1
' get color of field C
' if it is yellow the copy to another workbook
Do While aWorksheet.Cells(r1, c1 + 2) <> ""
Set aCell = aWorksheet.Cells(r1, c1 + 2)
aColor = aCell.Interior.ColorIndex
If aColor = 6 Then
bWorksheet.Cells(a1, b1).Value = "'" & aWorksheet.Cells(r1, c1 + 2).Value
a1 = a1 + 1
End If
r1 = r1 + 1
Loop
End Sub
But what i want to do is instead of moving the text of the yellow cell in row C to worksheet b, I want to move the whole row of any text in any cell thats bold in worksheet a to worksheet b
Example:
Worksheet A
A B C D E F G
N N Y N N N N
T T T S S T T
Workshhet B
A B C D E F G
N N Y N N N N
I hope this makes sense. This would really help me out ALOT, If not thanks for taking a look at it.
Last edited by The_Rookie; Jan 6th, 2005 at 03:45 PM.
-
Jan 4th, 2005, 04:50 PM
#2
Re: I could use a hand with this one.
Welcome to the Forums.
Once you have your row you can select the entire row, copy it, select the
other sheet, and paste the row in. Change the indexes to your variables, etc.
Just a demo of the mechanics involved.
VB Code:
Workbooks(1).Sheets("Sheet1").Rows(1).Select
Workbooks(1).Sheets("Sheet1").Rows(1).Copy
Workbooks(1).Sheets("Sheet2").Activate
Workbooks(1).Sheets("Sheet2").Paste Destination:=Workbooks(1).Sheets("Sheet2").Rows(1)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 4th, 2005, 05:10 PM
#3
Thread Starter
New Member
Re: I could use a hand with this one.
WOW! thanks for the quick reply RobDog888!!!
Thanks for the help but it looks like i would have to be specific with the row for it to copy the way you posted it there. And... what im trying to do is 1st locate the cell with bold text 2nd select the row that that cell is a part of then Paste it into the 2nd worksheet.
im a suppernoob if you cant tell...the code that i listed came from someone else who was trying to help but hes not availible anymore. I kinda understand it but some of it...most of it I dont. Im just being honest here.
but thanks for taking a look at it.
-
Jan 4th, 2005, 05:24 PM
#4
Re: I could use a hand with this one.
No prob.
I had some time so I integrated my code with yours. I think this is how it should go...
VB Code:
Dim aColor As Integer
Dim aCell As Range
Dim aWorksheet As Worksheet
Dim bWorksheet As Worksheet
Set aWorksheet = Worksheets("DATA")
Set bWorksheet = Worksheets("NegativeFMs")
r1 = 2
c1 = 1
a1 = 1
b1 = 1
' get color of field C
' if it is yellow the copy to another workbook
Do While aWorksheet.Cells(r1, c1 + 2) <> ""
Set aCell = aWorksheet.Cells(r1, c1 + 2)
aColor = aCell.Interior.ColorIndex
If aColor = 6 Then
bWorksheet.Cells(a1, b1).Value = "'" & aWorksheet.Cells(r1, c1 + 2).Value
aWorksheet.Activate 'Make sure we are on aWorksheet
aWorksheet.Rows(r1).Select
aWorksheet.Rows(r1).Copy
bWorksheet.Activate 'Switch to bWorksheet for the paste
bWorksheet.Paste Destination:=bWorksheet.Rows(a1)
aWorksheet.Activate 'Switch back
a1 = a1 + 1
End If
r1 = r1 + 1
Loop
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 4th, 2005, 05:59 PM
#5
Thread Starter
New Member
Re: I could use a hand with this one.
Hey Thanks man!!!
im almost there now...I just changed it so that instead of anythig yellow
VB Code:
aColor = aCell.Interior.ColorIndex
If aColor = 6 Then
..that it moves anything in bold text
VB Code:
aColor = aCell.Font.Bold
If aColor = True Then
Now how would i get it to recognize ANY cell with bold text on Worksheet A and copy that row to woeksheet B? Cause right now it will just copy the row of any bold text in any cell in Colum C
im learning slowly but surley but im stuck right here.
-
Jan 4th, 2005, 06:02 PM
#6
Re: I could use a hand with this one.
You would probably need to do a nested loop to loop accross the columns
looking at the cell in column A, B, C, ...
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 4th, 2005, 07:41 PM
#7
Thread Starter
New Member
Re: I could use a hand with this one.
can you give an example of a nested loop (yes, I am that green)? Im gonna do some searching on the web to see if i can figure it out.
-
Jan 4th, 2005, 09:41 PM
#8
Re: I could use a hand with this one.
Nested loop inside another loop example.
VB Code:
Dim x As Integer
Dim y As Integer
For x = 1 To 10
For y = 1 To 20
Msgbox x & y
Next
Next
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 5th, 2005, 02:43 PM
#9
Thread Starter
New Member
Re: I could use a hand with this one.
Ok i think im even more lost today.....It will still only copy the bold text in Colum C.
-
Jan 5th, 2005, 04:12 PM
#10
Re: I could use a hand with this one.
No, it is just an example of how to place a loop inside another loop.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 5th, 2005, 04:18 PM
#11
Re: I could use a hand with this one.
If I may stop in here....
Your code will only check one cell
VB Code:
Do While aWorksheet.Cells(r1, c1 + 2) <> ""
Set aCell = aWorksheet.Cells(r1, c1 + 2)
aColor = aCell.Interior.ColorIndex
If aColor = 6 Then
You never change the Cell r1,c1+2, use Robdog888's suggestion for nested loops. First you musr decide which range you want to check (how many rows, how many columns)
Knowing that you do something like
VB Code:
For i=1 To NumberofRowsToCheck
For j=1 to NumberOfColumnsToCheck
Set aCell = aWorksheet.Cells(i, j)
aColor = aCell.Font.Bold
If aColor = True Then
aWorksheet.Activate 'Make sure we are on aWorksheet
aWorksheet.Rows(i).Select
aWorksheet.Rows(i).Copy
bWorksheet.Activate 'Switch to bWorksheet for the paste
bWorksheet.Paste Destination:=bWorksheet.Rows(a1)
a1=a1+1
aWorksheet.Activate 'Switch back
End If
Next i
Next j
Hope that helps!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jan 5th, 2005, 04:40 PM
#12
Re: I could use a hand with this one.
I welcome anyone that wants to help anytime. 
You can use this code snippet to determine the last column used so your
inner loop will not miss any columns.
VB Code:
ActiveWorkbook.Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Column
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 5th, 2005, 05:10 PM
#13
Thread Starter
New Member
Re: I could use a hand with this one.
Ill give it a try but when i use the
VB Code:
For i=1 To NumberofRowsToCheck
For j=1 to NumberOfColumnsToCheck
Set aCell = aWorksheet.Cells(i, j)
Do i get rid of this all together?
VB Code:
Do While aWorksheet.Cells(r1, c1 + 2) <> ""
Set aCell = aWorksheet.Cells(r1, c1 + 2)
And for the rows to check I just want to check the whole sheet so would i put in there 65536?
Thanks for all your paitence help fellas....
-
Jan 6th, 2005, 03:53 PM
#14
Thread Starter
New Member
Re: I could use a hand with this one.
Got it to work for the most part but im using
instad of integer
and putting in 65536 for the rows.......
is there any way to speed it up ?
And Also if 2 cells in the same row have bold text it pastes' it to bworksheet
twice....is there any way to avoid that from happening?
heres the code so far
VB Code:
Dim aColor As Integer
Dim aCell As Range
Dim aWorksheet As Worksheet
Dim bWorksheet As Worksheet
Dim i As Long
Dim j As Integer
Set aWorksheet = Worksheets("Console")
Set bWorksheet = Worksheets("Results")
r1 = 2
c1 = 1
a1 = 1
b1 = 1
' get Text of FM field
' if it is BOLD the copy to another workbook
For i = 2 To 65536
For j = 1 To 13
Set aCell = aWorksheet.Cells(i, j)
aColor = aCell.Font.Bold
If aColor = True Then
aWorksheet.Activate 'Make sure we are on aWorksheet
aWorksheet.Rows(i).Select
aWorksheet.Rows(i).Copy
bWorksheet.Activate 'Switch to bWorksheet for the paste
bWorksheet.Paste Destination:=bWorksheet.Rows(a1)
a1 = a1 + 1
End If
Next
Next
End Sub
Thanks for all the help guys ive become a office hero thanks to you!!!
-
Jan 6th, 2005, 04:30 PM
#15
Re: I could use a hand with this one.
Sorry about the double pasting, I missed that.
you need to leave the column if you have fund one bold item.
Just insert a linwe like
after you have pasted
And for the speeding up use RobDog888s snippet the check for the last rownumber used.
it would look something like that:
VB Code:
Dim aColor As Integer
Dim aCell As Range
Dim aWorksheet As Worksheet
Dim bWorksheet As Worksheet
Dim i As Long
Dim j As Integer
Set aWorksheet = Worksheets("Console")
Set bWorksheet = Worksheets("Results")
r1 = 2
c1 = 1
a1 = 1
b1 = 1
' get Text of FM field
' if it is BOLD the copy to another workbook
For i = 2 To aWorksheet.Cells.SpecialCells(xlCellTypeLastCell).Row
For j = 1 To 13
Set aCell = aWorksheet.Cells(i, j)
aColor = aCell.Font.Bold
If aColor = True Then
aWorksheet.Activate 'Make sure we are on aWorksheet
aWorksheet.Rows(i).Select
aWorksheet.Rows(i).Copy
bWorksheet.Activate 'Switch to bWorksheet for the paste
bWorksheet.Paste Destination:=bWorksheet.Rows(a1)
a1 = a1 + 1
j=13
End If
Next
Next
End Sub
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jan 6th, 2005, 07:10 PM
#16
Thread Starter
New Member
Re: I could use a hand with this one.
Thanks for the Reply opus it works well
But Somethimes I have alot of data...and the scrren looks like its going to explode because i guess its checking back and forth for every cell then pasing it to bworkbook... Is there a way that we can do it where it shows the progress of the process on a status bar of some sort on aworksheet then when its complete...switch over to bworksheet for viewing the results?
Again thanks for your time and your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|