Align image objtable.cell VBS signature Outlook - vba

this my code to create a signature mail in outlook at GPO using script VBS.
was added a condition that if exist mobile number, appear of icon whatsapp with hiperlink. This hiperlink is ok, but I don't know how to align this whatsapp icon after number of whatsapp.
Script:
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
With objUser
strName = objUser.FullName
strPhone = objUser.TelephoneNumber
strFax = objUser.facsimileTelephoneNumber
strTitle = objUser.title
strMobile = objUser.Mobile
strMail = objuser.mail
strWeb = objuser.wWWHomePage
strDepartment = objUser.Department
strCompany = objUser.Company
strl = objUser.l
strco = objUser.co
End With
Set objword = CreateObject("Word.Application")
With objword
Set objDoc = .Documents.Add()
Set objSelection = .Selection
Set objEmailOptions = .EmailOptions
Set objRange = objDoc.Range()
objDoc.Tables.Add objRange,7,5
Set objTable = objDoc.Tables(1)
End With
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
With objSelection
'objTable.Columns.Width = 1024
objWord.InchesToPoints(2)
objTable.Cell(1, 1).Merge objTable.Cell(7, 1)
objTable.Cell(1, 2).Merge objTable.Cell(1, 2)
objTable.Cell(1, 2).Merge objTable.Cell(1, 3)
objTable.Cell(1, 2).Merge objTable.Cell(1, 4)
objTable.Cell(1, 2).Merge objTable.Cell(1, 5)
objTable.Cell(2, 2).Merge objTable.Cell(2, 3)
objTable.Cell(2, 2).Merge objTable.Cell(2, 4)
objTable.Cell(2, 2).Merge objTable.Cell(2, 5)
objTable.Cell(3, 2).Merge objTable.Cell(3, 3)
objTable.Cell(3, 2).Merge objTable.Cell(3, 4)
objTable.Cell(3, 2).Merge objTable.Cell(3, 5)
objTable.Cell(4, 2).Merge objTable.Cell(4, 3)
objTable.Cell(4, 2).Merge objTable.Cell(4, 4)
objTable.Cell(4, 2).Merge objTable.Cell(4, 5)
objTable.Cell(5, 2).Merge objTable.Cell(5, 3)
objTable.Cell(5, 2).Merge objTable.Cell(5, 4)
objTable.Cell(5, 2).Merge objTable.Cell(5, 5)
objTable.Cell(6, 2).Merge objTable.Cell(6, 3)
objTable.Cell(6, 2).Merge objTable.Cell(6, 4)
objTable.Cell(6, 2).Merge objTable.Cell(6, 5)
objSelection.InlineShapes.AddPicture("C:\Logo.png")
objTable.Cell(1, 2).Range.ParagraphFormat.SpaceAfter = 0
objTable.Cell(1, 2).Range.Font.Bold = True
objTable.Cell(1, 2).Range.Font.Size = "9"
objTable.Cell(1, 2).Range.Font.Name = "Arial"
objTable.Cell(1, 2).Range.Font.Color = RGB(0, 0, 0)
objTable.Columns(1).Width = objWord.InchesToPoints(1)
objTable.Cell(1, 2).Range.Text = strName
objTable.Cell(2, 2).Range.ParagraphFormat.SpaceAfter = 0
objTable.Cell(2, 2).Range.Font.Bold = True
objTable.Cell(2, 2).Range.Font.Size = "9"
objTable.Cell(2, 2).Range.Font.Name = "Arial"
objTable.Cell(2, 2).Range.Font.Color = RGB(110, 180, 63)
objTable.Columns(1).Width = objWord.InchesToPoints(1)
objTable.Cell(2, 2).Range.Text = strDepartment
objTable.Cell(3, 2).Range.ParagraphFormat.SpaceAfter = 0
objTable.Cell(3, 2).Range.Font.Size = "9"
objTable.Cell(3, 2).Range.Font.Name = "Arial"
objTable.Cell(3, 2).Range.Font.Color = RGB(0, 0, 0)
objTable.Columns(1).Width = objWord.InchesToPoints(1)
objTable.Cell(3, 2).Range.Text = strCompany
objTable.Cell(4, 2).Range.ParagraphFormat.SpaceAfter = 0
objTable.Cell(4, 2).Range.Font.Size = "9"
objTable.Cell(4, 2).Range.Font.Name = "Arial"
objTable.Cell(4, 2).Range.Font.Color = RGB(0, 0, 0)
objTable.Columns(1).Width = objWord.InchesToPoints(3)
Dim PhoneInformation
PhoneInformation = "99 9999 9999 | Ramal " & strPhone
IF strMobile <> "" Then
myobject= objSelection.Hyperlinks.Add(objSelection.InlineShapes.AddPicture("\\Server\NETLOGON\mail\whatsapp.png"), "https://wa.me/" & strMobile,,,"")
PhoneInformation = PhoneInformation + " | WhatsApp " + strMobile + myobject
End IF
objTable.Cell(4, 2).Range.Text = PhoneInformation
objTable.Cell(5, 2).Range.ParagraphFormat.SpaceAfter = 0
objTable.Cell(5, 2).Range.Font.Size = "9"
objTable.Cell(5, 2).Range.Font.Name = "Arial"
objTable.Cell(5, 2).Range.Font.Color = RGB(0, 0, 0)
objTable.Columns(1).Width = objWord.InchesToPoints(1)
objTable.Cell(5, 2).Range.Text = strMail
objTable.Cell(6, 2).Range.ParagraphFormat.SpaceAfter = 0
objTable.Cell(6, 2).Range.Font.Bold = True
objTable.Cell(6, 2).Range.Font.Size = "9"
objTable.Cell(6, 2).Range.Font.Name = "Arial"
objTable.Cell(6, 2).Range.Font.Color = RGB(110, 180, 63)
objTable.Columns(1).Width = objWord.InchesToPoints(1)
objTable.Cell(6, 2).Range.Text = "www"
.TypeText Chr(1)
.EndKey end_table
End With
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Ass", objSelection
objSignatureObject.NewMessageSignature = "Asss"
objSignatureObject.ReplyMessageSignature = "Ass"
objDoc.Saved = True
objword.Quit
Actually it gets like this:
I want it to stay that way:
Any idea to solved it?
thanks a lot.

Related

Excel VBA - Runtime error '1004' on If statement

I'm making a VBA program that changes the visuals of the excel file. There are some tags ("BN", "A", "C" etc.) which say how the rows/cells should be changed.
For example: the tag "A" means - set the cell font to "Arial", size 13... etc.
The program was working until I made some changes a while ago. Since then it's giving me always an runtime error. Has anyone any clue as to why?
The code:
Option Explicit
Sub macro1()
Dim rowIndex As Integer
Dim lastRowIndex As Integer
Dim offset As Integer
lastRowIndex = 2700
With ActiveSheet
For rowIndex = 1 To 3
Rows(1).EntireRow.Delete
Next rowIndex
With Cells.Font
.Name = "Arial"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Bold = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
End With
With Cells
.RowHeight = 11
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns(1).ColumnWidth = 13.5
Columns(2).ColumnWidth = 60
With Columns(3)
.HorizontalAlignment = xlCenter
.ColumnWidth = 5.5
End With
With Columns(4)
.HorizontalAlignment = xlRight
.ColumnWidth = 6.5
End With
With Columns(5)
.HorizontalAlignment = xlRight
.ColumnWidth = 6.5
End With
Columns(4).HorizontalAlignment = xlRight
Columns(5).HorizontalAlignment = xlRight
rowIndex = 1
offset = 0
Do While (rowIndex - offset) < lastRowIndex
If Cells(rowIndex, 5).Value = "A" Or Cells(rowIndex, 5).Value = "NAZOV" Or _
Cells(rowIndex, 5).Value = "C" Or Cells(rowIndex, 6).Value = "BN" Then
If Cells(rowIndex, 5).Value = "A" Then
Cells(rowIndex, 5).ClearContents
With Cells(rowIndex, 2).Font
.Name = "Arial Narrow"
.Size = 11
.Bold = True
.Color = RGB(204, 0, 0)
End With
With Cells(rowIndex, 2)
.RowHeight = 16
.HorizontalAlignment = xlCenter
End With
End If
If Cells(rowIndex, 5).Value = "NAZOV" Then
Cells(rowIndex, 5).ClearContents
With Cells(rowIndex, 2).Font
.Name = "Arial"
.Size = 9
.Bold = True
.Underline = xlUnderlineStyleSingle
.Color = RGB(0, 0, 153)
End With
With Cells(rowIndex, 2)
.RowHeight = 13
End With
End If
If Cells(rowIndex, 5).Value = "C" Then
Cells(rowIndex, 5).ClearContents
Cells(rowIndex, 6).ClearContents
Cells(rowIndex, 7).ClearContents
With Cells(rowIndex, 2).Font
.Name = "Arial Narrow"
.Size = 8
.Italic = True
.ColorIndex = 16
End With
With Cells(rowIndex, 2)
.RowHeight = 12
End With
End If
If Cells(rowIndex, 6) = "BN" Then
Cells(rowIndex, 6).ClearContents
If (Cells(rowIndex + 1, 5) <> "C") Then
Rows(rowIndex + 1).Insert
With Rows(rowIndex + 1)
.RowHeight = 3
.Font.Size = 2
End With
offset = offset + 1
Else
Rows(rowIndex + 2).Insert
With Rows(rowIndex + 2)
.RowHeight = 3
.Font.Size = 2
End With
offset = offset + 2
End If
End If
Else
Cells(rowIndex, 2).WrapText = True
Rows(rowIndex).AutoFit
End If
If Cells(rowIndex, 6).Value = "D" Then
Cells(rowIndex, 6).ClearContents
With Selection.Font
.Underline = xlUnderlineStyleSingle
.Bold = True
.Italic = False
End With
End If
If Cells(rowIndex, 6).Value = "E" Then
With Selection.Font
.Underline = xlUnderlineStyleSingle
.Bold = False
End With
End If
If Cells(rowIndex, 5).Value = "P" Then
Cells(rowIndex, 5).ClearContens
End If
If ( _
((Cells(rowIndex, 5) = Cells(rowIndex - 1, 5)) Or (Cells(rowIndex, 5) = Cells(rowIndex - 2, 5))) And _
((Cells(rowIndex, 4) = "" And Cells(rowIndex - 1, 4) <> "") Or (InStr(Cells(rowIndex, 2).Text, ">"))) And _
(Cells(rowIndex - 1, 2).Font.Size = 9) Or (Cells(rowIndex, 2).Font.Size = 9 And Cells(rowIndex - 1, 2).Font.Size = 9)) Then
With Cells(rowIndex, 2).Font
.Italic = True
.ColorIndex = 16
.Bold = False
.Size = 8
.Underline = False
End With
Cells(rowIndex, 2).WrapText = True
Rows(rowIndex).AutoFit
End If
rowIndex = rowIndex + 1
Loop
End With
End Sub
The runtime error appears on the last IF statement:
If ( _
((Cells(rowIndex, 5) = Cells(rowIndex - 1, 5)) Or (Cells(rowIndex, 5) = Cells(rowIndex - 2, 5))) And _
((Cells(rowIndex, 4) = "" And Cells(rowIndex - 1, 4) <> "") Or (InStr(Cells(rowIndex, 2).Text, ">"))) And _
(Cells(rowIndex - 1, 2).Font.Size = 9) Or (Cells(rowIndex, 2).Font.Size = 9 And Cells(rowIndex - 1, 2).Font.Size = 9)) Then

How to plot graphs on their corresponding sheet?

I am taking data from multiple spreadsheets and plotting them on a chart, for each of the respective spreadsheets. I want the data from Spreadsheet1 to plot a graph also on Spreadsheet1. Currently, my code plots all of the graphs on the last sheet, so the graphs for sheets 1,2,3, etc are all plotted on the last sheet. I am unsure how to fix this as I am new to VBA. I recorded a macro to get the code to plot the data.
here is my plotting code:
For j = 1 To size
'creates chart
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
ActiveSheet.Shapes("Chart 1").IncrementLeft 696.75
ActiveSheet.Shapes("Chart 1").IncrementTop -81.75
ActiveSheet.Shapes("Chart 1").ScaleWidth 1.3333333333, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 1").ScaleHeight 1.6909722222, msoFalse, _
msoScaleFromTopLeft
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""Length and Depth Data"""
ActiveChart.FullSeriesCollection(1).XValues = Worksheets("Case " & overview(j, 1)).Range("$R$10:$R$6000")
ActiveChart.FullSeriesCollection(1).Values = Worksheets("Case " & overview(j, 1)).Range("$S$10:$S$6000")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "=""B31G MAOP"""
ActiveChart.FullSeriesCollection(2).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(2).Values = Worksheets("Case " & overview(j, 1)).Range("$I$10:$I$159")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(3).Name = "=""B31G 1.25SF"""
ActiveChart.FullSeriesCollection(3).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(3).Values = Worksheets("Case " & overview(j, 1)).Range("$J$10:$J$159")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(4).Name = "=""B31G 1.39SF"""
ActiveChart.FullSeriesCollection(4).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(4).Values = Worksheets("Case " & overview(j, 1)).Range("$P$10:$P$159")
ActiveWindow.SmallScroll Down:=-126
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.SmallScroll Down:=6
Range("W32").Select
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
ActiveSheet.Shapes("Chart 2").IncrementLeft 311.25
ActiveSheet.Shapes("Chart 2").IncrementTop 213
ActiveWindow.SmallScroll Down:=18
Range("AD46:AD47").Select
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.Shapes("Chart 2").ScaleWidth 1.3145833333, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 2").ScaleHeight 1.4930555556, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.ChartObjects("Chart 2").Activate
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""Length and Depth Data"""
ActiveChart.FullSeriesCollection(1).XValues = Worksheets("Case " & overview(j, 1)).Range("$R$10:$R$6000")
ActiveChart.FullSeriesCollection(1).Values = Worksheets("Case " & overview(j, 1)).Range("$S$10:$S$6000")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "=""MB31G MAOP"""
ActiveChart.FullSeriesCollection(2).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(2).Values = Worksheets("Case " & overview(j, 1)).Range("$N$10:$N$159")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(3).Name = "=""MB31G 1.25SF"""
ActiveChart.FullSeriesCollection(3).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(3).Values = Worksheets("Case " & overview(j, 1)).Range("$O$10:$O$159")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(4).Name = "=""B31G 1.39SF"""
ActiveChart.FullSeriesCollection(4).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(4).Values = Worksheets("Case " & overview(j, 1)).Range("$P$10:$P$159")
ActiveWindow.SmallScroll Down:=-117
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.PlotArea.Select
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveWindow.SmallScroll Down:=9
ActiveChart.ChartTitle.Text = "B31G Burst Curve"
Selection.Format.TextFrame2.TextRange.Characters.Text = "B31G Burst Curve"
With Selection.Format.TextFrame2.TextRange.Characters(1, 16).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 16).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveWindow.SmallScroll Down:=-12
ActiveChart.ChartTitle.Text = "B31G Burst Curve"
Selection.Format.TextFrame2.TextRange.Characters.Text = "B31G Burst Curve"
With Selection.Format.TextFrame2.TextRange.Characters(1, 16).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 4).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(5, 12).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartTitle.Select
Application.CommandBars("Format Object").Visible = False
ActiveChart.ChartTitle.Text = "MB31G Burst Curve"
Selection.Format.TextFrame2.TextRange.Characters.Text = "MB31G Burst Curve"
With Selection.Format.TextFrame2.TextRange.Characters(1, 17).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 17).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
Next j
I would do this in a completely different way. But a quick fix to the wall of code that you provided would be adding this to the beginning just right after your for loop starts:
For j = 1 To size
'creates chart
Worksheets("Case " & overview(j, 1)).Activate
'Rest of the code would be the same
'...
Next j
You should read this question and its answers:
How to avoid selecting and activating in VBA?
You apply all instructions on the ActiveSheet. You can select specific sheets by Sheets(1).Activate or Sheets("sheet_name").Activate.
You can also iterate over all sheets by
For Each sht In ActiveWorkbook.Sheets
If sht.Name Like "..." Then ...
Next sht

Excel: Dynamically Update Chart Series in for loop

I have created a macro which will be used to create an individual chart for each of the over 2000 items who's data is stored in another Excel workbook. The macro goes through a for loop, creating a new chart, setting the chart series using the data from the other Excel workbook and then doing all of the formatting work after that. I am however still having a problem trying to dynamically update the series range after each for loop. A sample of the series is found below:
for i = 1 to Row.Count
ActiveChart.FullSeriesCollection(1).Values = _
"='[Simplified Interactive - V2.xlsm]Maint. FDC'!$D$2:$BA$2"
I was wondering how I would be able to modify the above static range, and make it dynamic so that the second chart uses data from row 3, the third chart uses data from row 4 and so on through the entire range.
Entire Code For Reference:
Sub Macro4()
Dim ws, ws2 As Worksheet
Dim graphName As String
Dim i As Integer
Dim srange As Range
Dim grp As Chart
Dim lw As Long
Set ws = Sheets("Interactive Data")
Set ws2 = Sheets("Graphs")
For i = 1 To 3 'Row.Count
ws2.Shapes.AddChart2(227, xlLine).Select
With ActiveChart
.Parent.Name = ws.Cells(i + 1, 1)
End With
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""Annual Inv."""
ActiveChart.FullSeriesCollection(1).Values = _
"='[Simplified Interactive - V2.xlsm]Maint. FDC'!$D$" & i + 1 & ":$BA$" & i + 1 '*****ADJUST THIS
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "=""Status Quo"""
ActiveChart.FullSeriesCollection(2).Values = _
"='[Simplified Interactive - V2.xlsm]No Maint. FDC'!$D$" & i + 1 & ":$BA$" & i + 1 '*****ADJUST THIS
ActiveChart.FullSeriesCollection(2).XValues = "=Graphs!$A$1:$AW$1"
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).ReversePlotOrder = True
ActiveChart.Axes(xlValue).Crosses = xlMaximum
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).TickLabels.Font.Color = RGB(0, 0, 0)
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlCategory).TickLabels.Font.Color = RGB(0, 0, 0)
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.SetElement (msoElementLegendRight)
ActiveChart.Legend.Select
ActiveChart.Legend.Select
Selection.Position = xlBottom
ActiveChart.Legend.LegendEntries(2).Select
ActiveChart.Legend.LegendEntries(1).Select
ActiveChart.Legend.Select
With Selection.Format.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
.Solid
End With
ActiveChart.ChartTitle.Select
Selection.Characters.Text = "Degradation"
With Selection.Format.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
.Solid
End With
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
ActiveChart.Axes(xlCategory).AxisTitle.Select
Selection.Format.TextFrame2.TextRange.Font.Bold = msoTrue
With Selection.Format.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
.Solid
End With
ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Text = "Year"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Year"
With Selection.Format.TextFrame2.TextRange.Characters(1, 4).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 4).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.SetElement msoElementPrimaryValueAxisTitleBelowAxis
ActiveChart.Axes(xlValue).AxisTitle.Select
With Selection.Format.TextFrame2.TextRange.Characters(1, 10).Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
.Solid
End With
Selection.Format.TextFrame2.TextRange.Font.Bold = msoTrue
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Condition"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Condition"
With Selection.Format.TextFrame2.TextRange.Characters(1, 30).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 8).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(9, 22).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.FullSeriesCollection(1).Select
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(192, 0, 0)
.Transparency = 0
End With
ActiveChart.FullSeriesCollection(2).Select
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 112, 192)
.Transparency = 0
End With
ActiveChart.ChartArea.Select
ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 53.6250393701, _
113.1250393701, 76.5, 15.75).Select
Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = _
"Status Quo"
Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 28).ParagraphFormat. _
FirstLineIndent = 0
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 28).Font
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Size = 8
.Name = "+mn-lt"
End With
Selection.ShapeRange.ScaleWidth 1.568627451, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 1.0476190476, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.IncrementLeft -6
Selection.ShapeRange.IncrementTop 6
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
.Solid
End With
ActiveChart.PlotArea.Select
ActiveChart.Shapes.Range(Array("TextBox 1")).Select
ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 58.8750393701, _
42.3750393701, 67.5, 12.75).Select
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.PlotArea.Select
ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 67.8750393701, _
45.6250393701, 104.25, 11.25).Select
Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = _
"Optimal"
Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 17).ParagraphFormat. _
FirstLineIndent = 0
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 7).Font
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Size = 8
.Name = "+mn-lt"
End With
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(8, 10).Font
.BaselineOffset = 0
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Size = 8
.Name = "+mn-lt"
End With
Selection.ShapeRange.ScaleHeight 1.4666666667, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleWidth 0.7553956835, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 1.0454545455, msoFalse, _
msoScaleFromBottomRight
Selection.ShapeRange.IncrementLeft -22.5
Selection.ShapeRange.IncrementTop 12.75
Range("R16").Select
Next i
End Sub
I was wondering how I would be able to modify the above static range, and make it dynamic so that the second chart uses data from row 3, the third chart uses data from row 4 and so on through the entire range.
By using a variable?
rw = 2
ActiveChart.FullSeriesCollection(1).Values = _
"='[Simplified Interactive - V2.xlsm]Maint. FDC'!$D$" & rw & ":$BA$" & rw
And if you want it "connected" to your For Loop i.e instead of using rw variable, you want to use i then
ActiveChart.FullSeriesCollection(1).Values = _
"='[Simplified Interactive - V2.xlsm]Maint. FDC'!$D$" & i & ":$BA$" & i
EDIT
the graph only plots the points for the first chart, but doesn't plot the series for charts 2 and beyond. The data does exist, so Any idea why it would be doing that? – Xcelrate
The code plots for all the 3 graphs for me. BTW, avoid the use of Activechart. Work with Objects. Here is a very basic example of how your code will look like.
Sub Sample()
Dim ws As Worksheet
Dim objChrt As ChartObject
Dim myChart As Chart
Dim chartTop As Long
Set ws = Sheets("Graphs")
'~~> This will define the "Left" of the chart
chartleft = 10
For i = 1 To 3
Set objChrt = ws.ChartObjects.Add(chartleft, 10, 200, 200)
Set myChart = objChrt.Chart
With myChart
.SeriesCollection.NewSeries
.FullSeriesCollection(1).Name = "Test"
.FullSeriesCollection(1).Values = "='Maint. FDC'!$D$" & i + 1 & ":$BA$" & i + 1
End With
chartleft = chartleft + 220
Next i
End Sub
Worksheet Maint. FDC
Worksheet Graphs
Interesting Read
ChartObjects.Add Method

#REF! pasted as value, but not seen as such when looping

I just released an Excel Add-In in my department today that I've been working on for the last 2+ months that checks for about 30 validation errors. I have the error trapping handled in all situations (as it appears right now), but I received a horrible wake-up call today as I received automatic emails (a feature I built into the error handling) for two vital bugs. I already posted a question about the first bug here and figured I'd start a fresh question for the second bug as it's about something unrelated to the first.
My code is as follows
Private Sub symbolCheck()
On Error GoTo ErrHandler
Application.StatusBar = "(3/16) Checking for invalid symbols"
Dim MyArray As Variant
Dim replacementsMade As Boolean
replacementsMade = False
MyArray = ActiveSheet.UsedRange
For i = LBound(MyArray) To UBound(MyArray)
For j = LBound(MyArray, 2) To UBound(MyArray, 2)
If MyArray(i, j) <> "" Then
'Apostrophe/Closing Single Quote
If InStr(1, MyArray(i, j), "’") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "’", Chr(39))
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Apostrophe
If InStr(1, MyArray(i, j), "`") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "`", Chr(39))
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Opening Single Quote
If InStr(1, MyArray(i, j), "‘") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "‘", Chr(39))
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Double Open Quotes
If InStr(1, MyArray(i, j), "“") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "“", """")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Double Closing Quotes
If InStr(1, MyArray(i, j), "”") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "”", """")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Dash
If InStr(1, MyArray(i, j), "–") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "–", "-")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Registered Trademark (R)
If InStr(1, MyArray(i, j), "®") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "®", "(R)")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Trademark (TM)
If InStr(1, MyArray(i, j), "™") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "™", "(TM)")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Degree Symbol
If InStr(1, MyArray(i, j), "°") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "°", " degrees")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Multiplication/x Symbol
If InStr(1, MyArray(i, j), "×") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "×", "x")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Upside-Down Question Mark Symbol
If InStr(1, MyArray(i, j), "¿") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "¿", "")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Solid Bullet Symbol
If InStr(1, MyArray(i, j), "•") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "•", "")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Triple Dots Symbol
If InStr(1, MyArray(i, j), "…") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "…", "...")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Euro Symbol
If InStr(1, MyArray(i, j), "€") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "€", "")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Linebreak Symbol
If InStr(1, MyArray(i, j), "|") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "|", ",")
If replacementsMade = False Then
replacementsMade = True
End If
End If
' 'Less Than Symbol
' If InStr(1, MyArray(i, j), "<") > 0 Then
' MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "<", "<")
' End If
' 'Greater Than Symbol
' If InStr(1, MyArray(i, j), ">") > 0 Then
' MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), ">", ">")
' End If
'Half Fraction
If InStr(1, MyArray(i, j), "½") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "½", " 1/2")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Three Quarter Fraction
If InStr(1, MyArray(i, j), "¾") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "¾", " 3/4")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'One Quarter Fraction
If InStr(1, MyArray(i, j), "¼") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "¼", " 1/4")
If replacementsMade = False Then
replacementsMade = True
End If
End If
End If
Next j
Next i
If replacementsMade Then
ActiveSheet.UsedRange = MyArray
End If
Set MyArray = Nothing
Exit Sub
ErrHandler:
Err.Raise Err.Number, "symbolCheck", Err.Description
End Sub
This bug occurs on the line
If MyArray(i, j) <> "" Then
When i = 209 and j = 60, so I did some poking around and looked inside the array to see what value was at that location. The value just says Error 2023 when I looked at the Watchlist values for the array slot. So, I looked at the cell that corresponded with those i and j values and alas I finally saw why the error was raised. The value in the cell was originally a formula with reference errors and since I copy/pasted as values prior to running this sub I thought I'd be fine. I had no idea that #REF! wasn't seen as plaintext?
Which leads me to my question
How can I handle this situation? More precisely, how would I be able to get rid of the #REF! values in a spreadsheet (without using Find/Replace) if #REF! isn't seen as plaintext even after being Copy/Pasted as a value?
Solution to Clear #REF! Values in Spreadsheet
You can use SpecialCells to clear the errors.
ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas, xlErrors).ClearContents 'Or change .Value to another value, delete cells, etc. as desired
Solution to handle #REF! Errors in Array
You can use the ISERROR() VBA function to capture each #REF! and then handle as desired.
Modify your code as follows:
Private Sub symbolCheck()
On Error GoTo ErrHandler
Application.StatusBar = "(3/16) Checking for invalid symbols"
Dim MyArray As Variant
Dim replacementsMade As Boolean
replacementsMade = False
MyArray = ActiveSheet.UsedRange
For i = LBound(MyArray) To UBound(MyArray)
For j = LBound(MyArray, 2) To UBound(MyArray, 2)
If IsError(MyArray(i, j)) Then
'Handle the #REF! here
ElseIf MyArray(i, j) <> "" Then
'Apostrophe/Closing Single Quote
If InStr(1, MyArray(i, j), "’") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "’", Chr(39))
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Apostrophe
If InStr(1, MyArray(i, j), "`") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "`", Chr(39))
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Opening Single Quote
If InStr(1, MyArray(i, j), "‘") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "‘", Chr(39))
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Double Open Quotes
If InStr(1, MyArray(i, j), "“") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "“", """")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Double Closing Quotes
If InStr(1, MyArray(i, j), "”") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "”", """")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Dash
If InStr(1, MyArray(i, j), "–") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "–", "-")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Registered Trademark (R)
If InStr(1, MyArray(i, j), "®") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "®", "(R)")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Trademark (TM)
If InStr(1, MyArray(i, j), "™") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "™", "(TM)")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Degree Symbol
If InStr(1, MyArray(i, j), "°") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "°", " degrees")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Multiplication/x Symbol
If InStr(1, MyArray(i, j), "×") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "×", "x")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Upside-Down Question Mark Symbol
If InStr(1, MyArray(i, j), "¿") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "¿", "")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Solid Bullet Symbol
If InStr(1, MyArray(i, j), "•") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "•", "")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Triple Dots Symbol
If InStr(1, MyArray(i, j), "…") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "…", "...")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Euro Symbol
If InStr(1, MyArray(i, j), "€") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "€", "")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Linebreak Symbol
If InStr(1, MyArray(i, j), "|") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "|", ",")
If replacementsMade = False Then
replacementsMade = True
End If
End If
' 'Less Than Symbol
' If InStr(1, MyArray(i, j), "<") > 0 Then
' MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "<", "<")
' End If
' 'Greater Than Symbol
' If InStr(1, MyArray(i, j), ">") > 0 Then
' MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), ">", ">")
' End If
'Half Fraction
If InStr(1, MyArray(i, j), "½") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "½", " 1/2")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Three Quarter Fraction
If InStr(1, MyArray(i, j), "¾") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "¾", " 3/4")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'One Quarter Fraction
If InStr(1, MyArray(i, j), "¼") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "¼", " 1/4")
If replacementsMade = False Then
replacementsMade = True
End If
End If
End If
Next j
Next i
If replacementsMade Then
ActiveSheet.UsedRange = MyArray
End If
Set MyArray = Nothing
Exit Sub
ErrHandler:
Err.Raise Err.Number, "symbolCheck", Err.Description
End Sub

How can I detect a merged cell above a select line using VBA?

From the image below, I want to write a vba where cells in the column b will be equal to group above. So for example, column b for Activity 1.1 and Activity 1.2 would be equal to Group 1, and column b for Activity 2.1 and Activity 2.2 would be equal to Group 2.
c d e f g h i
Any ideas on where to start? Currently I have a two macros: One creates a group below a selected group and the other creates a line below a selected line. I'm thinking that when creating a new line I could somehow equate column b to the closest merged cell above my new line.
How could I find the closest merged cell above a selected row?
The code to create a new line is below:
Sub newLine()
Dim currCell As Integer
Dim newCell As Integer
currCell = ActiveCell.Select
Selection.Offset(1).EntireRow.Insert
ActiveCell.Offset(1, 0).Select
Cells(Selection.Row, 3).FormulaR1C1 = "=IF(RC4=""Complete"",1,IF(RC4=""Late"",2,IF(RC4=""At Risk"",3,IF(RC4=""On Schedule"",4,5))))"
With Cells(Selection.Row, 3)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=1"
.FormatConditions(1).Interior.Color = RGB(0, 112, 192)
.FormatConditions(1).Font.Color = RGB(0, 112, 192)
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=2"
.FormatConditions(2).Interior.Color = RGB(192, 0, 0)
.FormatConditions(2).Font.Color = RGB(192, 0, 0)
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=3"
.FormatConditions(3).Interior.Color = RGB(255, 192, 0)
.FormatConditions(3).Font.Color = RGB(255, 192, 0)
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=4"
.FormatConditions(4).Interior.Color = RGB(146, 208, 80)
.FormatConditions(4).Font.Color = RGB(146, 208, 80)
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=5"
.FormatConditions(5).Interior.Color = RGB(255, 255, 255)
.FormatConditions(5).Font.Color = RGB(255, 255, 255)
End With
Cells(Selection.Row, 4).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="Complete, Late, At Risk, On Schedule"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = "Select Status"
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Cells(Selection.Row, 4) = "[Enter Status]"
Cells(Selection.Row, 4).HorizontalAlignment = xlLeft
Cells(Selection.Row, 5) = "[Enter Activity]"
Cells(Selection.Row, 5).HorizontalAlignment = xlLeft
Cells(Selection.Row, 6) = "[Enter Task]"
Cells(Selection.Row, 6).HorizontalAlignment = xlLeft
Cells(Selection.Row, 7) = "[Enter Responsability]"
Cells(Selection.Row, 7).HorizontalAlignment = xlLeft
Cells(Selection.Row, 8) = "[Enter Start Date]"
Cells(Selection.Row, 8).HorizontalAlignment = xlRight
Cells(Selection.Row, 9) = "[Enter Comp Date]"
Cells(Selection.Row, 9).HorizontalAlignment = xlRight
Range(Cells(Selection.Row, 4), Cells(Selection.Row, 9)).Font.Bold = False
Range(Cells(Selection.Row, 4), Cells(Selection.Row, 9)).Font.Size = 8
Range(Cells(Selection.Row, 4), Cells(Selection.Row, 9)).RowHeight = 11.25
Range(Cells(Selection.Row, 4), Cells(Selection.Row, 7)).HorizontalAlignment = xlLeft
Range(Cells(Selection.Row, 4), Cells(Selection.Row, 7)).NumberFormat = "General"
Range(Cells(Selection.Row, 8), Cells(Selection.Row, 9)).HorizontalAlignment = xlRight
Range(Cells(Selection.Row, 8), Cells(Selection.Row, 9)).NumberFormat = "m/d/yyyy"
End Sub
Any ideas?
Thank you!
MergeCells can help you out here.
Sub WhichLineIsMerged()
Dim row As Long
For row = ActiveCell.row To 1 Step -1
If Cells(row, 1).MergeCells Then
MsgBox "There are merged cells in row " & row
End If
Next row
End Sub
This sub only checks one cell on each line. As written, it checks Column A. You can adjust as needed.
In case anyone was interested, here's how I solved this:
Sub testGroupNum()
Dim i As Long
Dim LastRow As Integer
Dim startRow As Integer
LastRow = Cells(Rows.Count, "H").End(xlUp).Row
startRow = Selection.Row
For i = startRow To 11 Step -1
If Cells(i, 4).MergeCells = True Then
Cells(startRow, 2) = Cells(i, 4)
Exit For
End If
Next
End Sub