cdhoughton
Board Regular
- Joined
- Dec 5, 2003
- Messages
- 170
I have some code that requires slight adjustment:
I have a table, C columns wide by L rows. I want code that looks in each cell, checks if it is bold, writes some text in a target cell if it is "bold" or "not bold", then checks the same cell if it is italic, then notes that one down from the previous target cell, and so on.
I need to go through each column in row 1, then each column in row 2 until row L. If anyone can help with the code below, or provide a simpler example I can adapt, I'd be much appreciated!!
PS I added the CellAddress to identify where the for next loop was looking, and it's not going to the right cells at all!! Any help?!?!
---------------------------------------------------------
Sub CheckCellFormat()
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim C As Integer
Dim L As Integer
Dim Rng As Range
Dim DestinRng As Range
Dim D As Integer
Dim LineNo As Integer
Dim NewStartRng As Range
Set NewStartRng = Sheets("Note Formatter").Range("tabstart")
Set Rng = Sheets("Note Formatter").Range("tabstart")
Set DestinRng = Sheets("INPUT").Range("startlineinfo").Offset(0, 1)
LineNo = 1
L = Sheets("INPUT").Range("NoOfLines") + 2
C = Sheets("INPUT").Range("NoOfCols") + 1
D = -C
For x = 1 To L
For y = 1 To C
If Rng.Font.Bold = True Then
DestinRng.Value = "Bold" & Rng.Address
Else: DestinRng.Value = "Not Bold" & Rng.Address
End If
Set DestinRng = DestinRng.Offset(1, 0)
If Rng.Font.Italic = True Then
DestinRng.Value = "Italic" & Rng.Address
Else: DestinRng.Value = "Not Italic" & Rng.Address
End If
Set DestinRng = DestinRng.Offset(1, 0)
If Rng.HorizontalAlignment = xlLeft Then
DestinRng.Value = "Left" & Rng.Address
ElseIf Rng.HorizontalAlignment = xlRight Then
DestinRng.Value = "Right" & Rng.Address
ElseIf Rng.HorizontalAlignment = xlCenter Then
DestinRng.Value = "Cent" & Rng.Address
End If
Set DestinRng = DestinRng.Offset(1, 0)
Rng = Rng.Offset(0, 1)
Next y
Set NewStartRng = NewStartRng.Offset(1, 0)
Set Rng = NewStartRng
Next x
End Sub
I have a table, C columns wide by L rows. I want code that looks in each cell, checks if it is bold, writes some text in a target cell if it is "bold" or "not bold", then checks the same cell if it is italic, then notes that one down from the previous target cell, and so on.
I need to go through each column in row 1, then each column in row 2 until row L. If anyone can help with the code below, or provide a simpler example I can adapt, I'd be much appreciated!!
PS I added the CellAddress to identify where the for next loop was looking, and it's not going to the right cells at all!! Any help?!?!
---------------------------------------------------------
Sub CheckCellFormat()
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim C As Integer
Dim L As Integer
Dim Rng As Range
Dim DestinRng As Range
Dim D As Integer
Dim LineNo As Integer
Dim NewStartRng As Range
Set NewStartRng = Sheets("Note Formatter").Range("tabstart")
Set Rng = Sheets("Note Formatter").Range("tabstart")
Set DestinRng = Sheets("INPUT").Range("startlineinfo").Offset(0, 1)
LineNo = 1
L = Sheets("INPUT").Range("NoOfLines") + 2
C = Sheets("INPUT").Range("NoOfCols") + 1
D = -C
For x = 1 To L
For y = 1 To C
If Rng.Font.Bold = True Then
DestinRng.Value = "Bold" & Rng.Address
Else: DestinRng.Value = "Not Bold" & Rng.Address
End If
Set DestinRng = DestinRng.Offset(1, 0)
If Rng.Font.Italic = True Then
DestinRng.Value = "Italic" & Rng.Address
Else: DestinRng.Value = "Not Italic" & Rng.Address
End If
Set DestinRng = DestinRng.Offset(1, 0)
If Rng.HorizontalAlignment = xlLeft Then
DestinRng.Value = "Left" & Rng.Address
ElseIf Rng.HorizontalAlignment = xlRight Then
DestinRng.Value = "Right" & Rng.Address
ElseIf Rng.HorizontalAlignment = xlCenter Then
DestinRng.Value = "Cent" & Rng.Address
End If
Set DestinRng = DestinRng.Offset(1, 0)
Rng = Rng.Offset(0, 1)
Next y
Set NewStartRng = NewStartRng.Offset(1, 0)
Set Rng = NewStartRng
Next x
End Sub