How to create Line charts? - excel

I would like to create Line charts (2-D Line with Markers) for a set of records.
Screenshot of Excel tab
(a) Every three rows represent a set to be charted. The fourth column, though it appears, need not be charted. In the screenshot there are 18 rows, which is six sets of records.
(b) One Line chart required for each set of records. Hence a total of six charts to be created automatically.
(c) Also, the charts are to be created in different Excel tabs. Three charts per tab, hence this should create two Excel tabs with three charts placed in each tab.

I have prepared some code for automatic charts generation using VBA macro in excel see if this helps.
Below code will generate charts for data available in excel:
Dim Startrow As String
Dim Lastrow As String
Dim Lastcolumn As String
Dim ws1 As String
Dim cs2 As String
Dim cs3 As String
Dim ws(100)
Dim count As String
Dim i As Integer
Sub Final()
For j = 2 To Sheets.count
count = Sheets.count
Sheet1.Activate
Cells(i, 1) = Sheets(i).Name
'ws(i) = Sheets(i).Name
'MsgBox Sheets.Count
'MsgBox count
'MsgBox ws(i)
Next
For i = 2 To count
MsgBox count
MsgBox i
Sheet1.Activate
ws(i) = Cells(i, 1)
Sheets(ws(i)).Activate
'Sheets(ws(i)).Activate
MsgBox ws(i)
'MsgBox Range("B1")
'MsgBox IsEmpty(Range("B2"))
If IsEmpty(Range("B1")) = False Then
Startrow = 2
'MsgBox Startrow
Lastrow = Cells(Rows.count, 1).End(xlUp).Row
'MsgBox Lastrow
Lastcolumn = Split(Columns(Range("A1").End(xlToRight).Column).Address(, False), ":")(1)
'MsgBox Lastcolumn
Call test1
MsgBox i
End If
Next
End Sub
Function test1()
Dim letter As String
Dim letter1 As String
Dim letter2 As String
Dim letter3 As String
Dim x As Integer
MsgBox ws(i)
x = Range(Lastcolumn & 1).Column
'MsgBox x
Dim cs As Worksheet
Set cs = ThisWorkbook.Sheets.Add
'ws.name = "PrivateBytes_000005_Charts"
'ws2 = "PrivateBytes_000005_Charts"
cs.Name = ws(i) + "_Charts"
'MsgBox ws.Name
cs2 = ws(i) + "_Charts"
MsgBox cs2
cs3 = ws(i)
MsgBox cs3
If x < 27 Then
For i = 2 To x
letter3 = Chr(64 + i)
'chart command
Sheets(cs2).Activate
ActiveSheet.Shapes.AddChart2(227, xlLineStacked).Select
ActiveChart.SetSourceData Source:=Sheets(cs3).Range("A" & Startrow & ":A" & Lastrow & "," & letter3 & Startrow & ":" & letter3 & Lastrow)
With ActiveChart
.HasTitle = True
Sheets(cs3).Activate
.ChartTitle.Text = Range(letter3 & "1").Value
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
Next
End If
If x >= 27 Then
For i = 2 To 26
letter3 = Chr(64 + i)
'chart command
Sheets(cs2).Activate
ActiveSheet.Shapes.AddChart2(227, xlLineStacked).Select
ActiveChart.SetSourceData Source:=Sheets(cs3).Range("A" & Startrow & ":A" & Lastrow & "," & letter3 & Startrow & ":" & letter3 & Lastrow)
With ActiveChart
.HasTitle = True
Sheets(cs3).Activate
.ChartTitle.Text = Range(letter3 & "1").Value
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
Next
For i = 27 To x
letter3 = Chr(Int((i - 1) / 26) + 64) & Chr(((i - 1) Mod 26) + 65)
'MsgBox letter3
'chart command
Sheets(cs2).Activate
ActiveSheet.Shapes.AddChart2(227, xlLineStacked).Select
ActiveChart.SetSourceData Source:=Sheets(cs3).Range("A" & Startrow & ":A" & Lastrow & "," & letter3 & Startrow & ":" & letter3 & Lastrow)
With ActiveChart
.HasTitle = True
Sheets(cs3).Activate
.ChartTitle.Text = Range(letter3 & "1").Value
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
Next
End If
Sheets(cs.Name).Activate
ActiveChart.Parent.Name = "Test1"
Call AutoSpace_Shapes_Vertical
'Return
'Unload UserForm1
End Function
Function AutoSpace_Shapes_Vertical()
'Automatically space and align shapes
Sheets(cs2).Activate
ActiveSheet.ChartObjects("Test1").Activate
ActiveSheet.Shapes.SelectAll
Dim shp As Shape
Dim lCnt As Long
Dim dTop As Double
Dim dLeft As Double
Dim dHeight As Double
Const dSPACE As Double = 8
'Check if shapes are selected
If TypeName(Selection) = "Range" Then
MsgBox "Please select shapes before running the macro."
Exit Function
End If
'Set variables
lCnt = 1
'Loop through selected shapes (charts, slicers, timelines, etc.)
For Each shp In Selection.ShapeRange
With shp
'If not first shape then move it below previous shape and align left.
If lCnt > 1 Then
.Top = dTop + dHeight + dSPACE
.Left = dLeft
End If
'Store properties of shape for use in moving next shape in the collection.
dTop = .Top
dLeft = .Left
dHeight = .Height
End With
'Add to shape counter
lCnt = lCnt + 1
Next shp
End Function
'End Sub
'End Sub
enter image description here

Related

Clear cells from ith row

I have the code below but once its executed I need to clear all Columns from A to G from the ith row
Sub GetPic()
Dim fNameAndPath As String
Dim img As Object
Dim CommodityName1 As String, T1 As String
Dim myDir As String
Dim i As Integer, j As Integer
Worksheets("Picture").Activate
Dim shape As Excel.shape
Dim datarangeb As Range
Dim numberofcells As Integer
Set datarangeb = Sheets("Data").Range("b:b")
numberofcells = WorksheetFunction.CountA(datarangeb)
numberofcells = numberofcells * 12 + 1
For Each shape In ActiveSheet.Shapes
shape.Delete
Next
j = 7
For i = 2 To numberofcells
myDir = "C:\Users\User\Desktop\ESTIMATING SHEETS\test\rebar shapes" & "\"
CommodityName1 = Range("a" & i)
T1 = ".png"
fNameAndPath = myDir & CommodityName1 & T1
On Error GoTo errormessage:
Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
On Error GoTo errormessage:
With img
'Move and Resize Image
.ShapeRange.LockAspectRatio = msoFalse
.Left = ActiveSheet.Range("d" & i).Left
.Top = ActiveSheet.Range("d" & i).Top
.Width = ActiveSheet.Range("d" & i & ":g" & i).Width
.Height = ActiveSheet.Range("d" & i & ":g" & j).Height
errormessage:
If Err.Number = 1004 Then
Exit Sub
MsgBox "File does not exist." & vbCrLf & "Check the name of the rebar!"
End If
End With
Application.ScreenUpdating = True
i = i + 11
j = j + 12
Next i
i = i - 1
End Sub
So Im not too sure what the syntax is to clear up to the end of column G. One way is to just clear it up to G6000 or some large number but I want the code to execute not using too much memory
Sub schedulemacro()
Dim k As Integer
Dim data As Worksheet, Picture As Worksheet, sheet1 As Worksheet
Dim i As Integer, j As Integer
Set data = Sheets("Data")
Set Picture = Sheets("Picture")
Set sheet1 = Sheets("Sheet 1")
j = 13
Picture.Activate
data.Cells(2, 2) = sheet1.Cells(2, 1)
k = WorksheetFunction.CountA(sheet1.Range("b:b")) - 1
sheet1.Range("a2:k" & k + 1).copy
data.Range("b2:k" & k + 1).PasteSpecial xlPasteValues
If k = 0 Then
MsgBox ("Please place data into the data sheet or export from revit!")
data.Activate
data.Range("a2:l2").Select
Exit Sub
End If
Picture.Range("A1:G12").Select
Selection.copy
For i = 1 To k
data.Range("a" & i + 1) = i
Picture.Range("a" & j).PasteSpecial
j = j + 12
Next i
j = 1
i = 2
k = k + 1
For i = 2 To k
Picture.Cells(j, 1) = data.Range("A" & i)
j = j + 12
Next i
Call GetPic
End Sub
Sub GetPic()
Dim fNameAndPath As String
Dim img As Object
Dim CommodityName1 As String, T1 As String
Dim myDir As String
Dim i As Integer, j As Integer
Worksheets("Picture").Activate
Dim shape As Excel.shape
Dim datarangeb As Range
Dim numberofcells As Integer
Set datarangeb = Sheets("Data").Range("b:b")
numberofcells = WorksheetFunction.CountA(datarangeb)
numberofcells = (numberofcells - 1) * 12 + 1
For Each shape In ActiveSheet.Shapes
shape.Delete
Next
j = 7
For i = 2 To numberofcells
myDir = "C:\Users\User\Desktop\ESTIMATING SHEETS\test\rebar shapes" & "\"
CommodityName1 = Range("a" & i)
T1 = ".png"
fNameAndPath = myDir & CommodityName1 & T1
On Error GoTo errormessage:
Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
On Error GoTo errormessage:
With img
'Move and Resize Image
.ShapeRange.LockAspectRatio = msoFalse
.Left = ActiveSheet.Range("d" & i).Left
.Top = ActiveSheet.Range("d" & i).Top
.Width = ActiveSheet.Range("d" & i & ":g" & i).Width
.Height = ActiveSheet.Range("d" & i & ":g" & j).Height
errormessage:
If Err.Number = 1004 Then
Exit Sub
MsgBox "File does not exist." & vbCrLf & "Check the name of the rebar!"
End If
End With
Application.ScreenUpdating = True
i = i + 11
j = j + 12
Next i
i = i - 1
Worksheets("Picture").Range("A" & i & ":i27000").Clear
End Sub

How do i add text to specific cells already containing text given certain criteria?

Worksheet picture
I want to add the text LAURA to column E in front of the existing text in the column when it gets copied to the targeted worksheet:
Private Sub CommandButton1_Click()
Dim wsSource, wsTarget As Worksheet
Dim i, iLastSource, iRowTarget, count As Long
Dim cell As Range
Set wsSource = Worksheets("Stig Jan")
iLastSource = wsSource.Cells(Rows.count, 1).End(xlUp).Row
Set wsTarget = Worksheets("Laura Jan")
count = 0
With wsSource
iRowTarget = wsTarget.Cells(Rows.count, 1).End(xlUp).Row + 1
For i = 36 To iLastSource
Set cell = .Cells(i, 4)
If cell.Font.Bold = False Then
If cell.Value = "Fælles" Or cell.Value = "Lagt Ud" Then
wsTarget.Range("A" & iRowTarget & ":H" & iRowTarget).Value = .Range("A" & i & ":H" & i).Value
wsTarget.Range("D" & iRowTarget).ClearContents
**wsTarget.Range("E" & iRowTarget).Value = "LAURA. " & cell.Value**
iRowTarget = iRowTarget + 1
count = count + 1
End If
End If
If cell.Value = "Fælles" Or cell.Value = "Lagt Ud" Then
wsSource.Rows(i).Columns("D").Font.Bold = True
End If
Next
As of now it copies the value in column D instead. So LAURA + Column D

VBA Code: Insert image to cell based on url entered in form

I have coded a form for entering product information that allows the user to browse for a file location and inserts that location into a cell on the sheet once submitted. I would like to code the from so that the a later cell displays the image file. I found a fantastic resource that has code that does what I want. The resource is located at the following link: https://techcommunity.microsoft.com/t5/excel/convert-image-url-to-actual-image-in-excel/m-p/309020
The problem is that once the code is ran, it updates all the links on a sheet, creating duplicate images that are stacked. I would like to alter and add the code to my form code so that only the new image url is added once the form is submitted.
Here is the code found at the link above:
Sub URLPictureInsert()
'Updateby Extendoffice 20161116
'Update #1 by Haytham Amairah in 20180104
'Update #2 by Haytham Amairah in 20180108
Dim Pshp As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
Set Rng = ActiveSheet.Range("A2:A140")
For Each cell In Rng
filenam = cell
ActiveSheet.Pictures.Insert(filenam).Select
Set Pshp = Selection.ShapeRange.Item(1)
Pshp.Placement = xlMoveAndSize
If Pshp Is Nothing Then GoTo lab
xCol = cell.Column + 1
Set xRg = Cells(cell.Row, xCol)
With Pshp
.LockAspectRatio = msoFalse
.Width = 60
.Height = 30
.Top = xRg.Top + (xRg.Height - .Height) / 2
.Left = xRg.Left + (xRg.Width - .Width) / 2
End With
lab:
Set Pshp = Nothing
Range("A2").Select
Next
Application.ScreenUpdating = True
End Sub
Here is the section of code I currently have that I would like to add the above code to:
Dim ComputerId As String
ComputerId = Environ$("ComputerName")
Dim Specs_Number As String
Specs_Number = Left(Me.ComboBoxSpecification.Value, Application.Find(" - ", Me.ComboBoxSpecification.Value) - 1)
Dim Specs_Name As String
Specs_Name = Right(Me.ComboBoxSpecification.Value, (Len(Me.ComboBoxSpecification.Value) - 2) - Application.Find(" - ", Me.ComboBoxSpecification.Value))
Dim RowCount As Long
RowCount = Worksheets("FormData").Range("A1").CurrentRegion.Rows.Count
Select Case Me.ComboBoxDivision
Case "DIVISION 22 - PLUMBING"
Set ws = Sheets("Div-22")
Case "DIVISION 23 - HEATING VENTILATING AND AIR CONDITIONING"
Set ws = Sheets("Div-23")
LastRow = ws.Range("C" & Rows.Count).End(xlUp).Row + 1
ws.Range("b" & LastRow).Value = Specs_Number
ws.Range("c" & LastRow).Value = Specs_Name
AddLink ws.Range("i" & LastRow), Me.TextBoxPicture_File_Link.Value
ws.Range("o" & LastRow).Value = Me.TextBoxSales_Rep_Email.Value
Unload Product_Information_Form
Start_Form.Show
End Sub
And here is an example of what I would like (bottom half of code, the "ws.Range("r" & LastRow).Value = URLPictureInsert()" line of code):
Dim ComputerId As String
ComputerId = Environ$("ComputerName")
Dim Specs_Number As String
Specs_Number = Left(Me.ComboBoxSpecification.Value, Application.Find(" - ", Me.ComboBoxSpecification.Value) - 1)
Dim Specs_Name As String
Specs_Name = Right(Me.ComboBoxSpecification.Value, (Len(Me.ComboBoxSpecification.Value) - 2) - Application.Find(" - ", Me.ComboBoxSpecification.Value))
Dim RowCount As Long
RowCount = Worksheets("FormData").Range("A1").CurrentRegion.Rows.Count
Select Case Me.ComboBoxDivision
Case "DIVISION 22 - PLUMBING"
Set ws = Sheets("Div-22")
Case "DIVISION 23 - HEATING VENTILATING AND AIR CONDITIONING"
Set ws = Sheets("Div-23")
LastRow = ws.Range("C" & Rows.Count).End(xlUp).Row + 1
ws.Range("b" & LastRow).Value = Specs_Number
ws.Range("c" & LastRow).Value = Specs_Name
AddLink ws.Range("i" & LastRow), Me.TextBoxPicture_File_Link.Value
ws.Range("o" & LastRow).Value = Me.TextBoxSales_Rep_Email.Value
ws.Range("r" & LastRow).Value = URLPictureInsert()
Unload Product_Information_Form
Start_Form.Show
End Sub
Sub URLPictureInsert()
Dim Pshp As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
Set Rng = ActiveSheet.Range("J2:J140")
For Each cell In Rng
filenam = cell
ActiveSheet.Pictures.Insert(filenam).Select
Set Pshp = Selection.ShapeRange.Item(1)
Pshp.Placement = xlMoveAndSize
If Pshp Is Nothing Then GoTo lab
xCol = cell.Column + 1
Set xRg = Cells(cell.Row, xCol)
With Pshp
.LockAspectRatio = msoFalse
.Width = 60
.Height = 60
.Top = xRg.Top + (xRg.Height - .Height) / 3
.Left = xRg.Left + (xRg.Width - .Width) / 3
End With
lab:
Set Pshp = Nothing
Range("J2").Select
Next
Application.ScreenUpdating = True
End Sub
Any help would be appreciated. If possible, please explain in a clear and detailed way since I am still very much a novice at VBA coding and a beginner at coding in general.
Here's a simple demo of calling a sub to insert a picture from a given URL at a specific location.
You can call URLPictureInsert from your code and pass it the cell with the URL and the cell where the image should go.
Sub Tester()
'get an image URL from A3 and put the image at C3
URLPictureInsert Range("a3"), Range("C3")
End Sub
Sub URLPictureInsert(rngURL As Range, rngWhere As Range)
Dim shp As Shape
On Error Resume Next
Set shp = rngWhere.Parent.Shapes.AddPicture(rngURL.Value, LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=rngWhere.Left, Top:=rngWhere.Top, _
Width:=-1, Height:=-1)
On Error GoTo 0
If Not shp Is Nothing Then
shp.Width = 30
shp.Height = 30
End If
End Sub

concatenate vba excel keep format

I am building on some code, partly cut and paste from other posts. I need to concatenate with a VBA code keeping the format and running through rows to output in last cell in each row. (Can't paste image) so hope description is clear:
In A1:D1 values are RED,BLUE,GREEN
In A2:D2 Values are YELLOW,PURPLE,ORANGE
OUTPUT IN E1 should concatenate these values, keeping font colour. Each value should have "ALT ENTR" to give line break.
Next row should be displayed in E2, and so on
'************************************************************************************
Sub test()
Dim rng As Range: Set rng = Application.Range("a1:c1") 'Not yet looping
Dim row As Range
For Each row In rng.Rows
'Debug.Print col.Column
Call concatenate_cells_formats(Cells(1, 4), rng) 'Not yet looping
Next row
End Sub
Sub concatenate_cells_formats(cell As Range, source As Range)
'Anon
Dim c As Range
Dim i As Integer
i = 1
With cell
.Value = vbNullString
.ClearFormats
For Each c In source
.Value = .Value & " " & Trim(c)
Next c
.Value = Trim(.Value)
For Each c In source
With .Characters(Start:=i, Length:=Len(Trim(c))).Font
.Name = c.Font.Name
.FontStyle = c.Font.FontStyle
.Size = c.Font.Size
.Strikethrough = c.Font.Strikethrough
.Superscript = c.Font.Superscript
.Subscript = c.Font.Subscript
.OutlineFont = c.Font.OutlineFont
.Shadow = c.Font.Shadow
.Underline = c.Font.Underline
.ColorIndex = c.Font.ColorIndex
End With
.Characters(Start:=i + Len(c), Length:=1).Font.Size = 1
i = i + Len(Trim(c)) + 1
Next c
End With
End Sub
'*****************************************************************************
Option Explicit
Sub concColour()
Dim i As Long, j As Long, s As Long, l As Long, clr As Long, vals As Variant
With Worksheets("sheet4")
For i = 1 To .Cells(.Rows.Count, "A").End(xlUp).Row
vals = Application.Transpose(Application.Transpose(Intersect(.Range("A:D"), .Rows(i)).Value2))
.Cells(i, "E") = Join(vals, vbLf)
s = 1
For j = LBound(vals) To UBound(vals)
l = Len(vals(j))
clr = .Cells(i, "A").Offset(0, j - 1).Font.Color
With .Cells(i, "E").Characters(Start:=s, Length:=l).Font
.Color = clr
End With
s = s + l + 1
Next j
.Cells(i, "E").Font.Size = 4
Next i
End With
End Sub
enter image description here
I think you require something like this. Change source font and formats as per your requirement.
Sub Adding_T()
Dim lena As Integer
Dim lenc As Integer
Dim lend As Integer
Dim lene As Integer
Dim LastRow As Long
Dim nrow As Long
With Worksheets("Sheet2") 'Change sheet as per your requirement
LastRow = .Cells(.Rows.Count, "A").End(xlUp).row
For nrow = 1 To LastRow
.Range("E" & nrow) = .Range("A" & nrow).Value2 & Chr(13) & Chr(10) & .Range("B" & nrow).Value2 & _
Chr(13) & Chr(10) & .Range("C" & nrow).Value2 & Chr(13) & Chr(10) & .Range("D" & nrow).Value2
lena = Len(.Range("A" & nrow).Value2)
lenc = lena + 2 + Len(.Range("B" & nrow).Value2)
lend = lenc + 2 + Len(.Range("C" & nrow).Value2)
lene = lend + 2 + Len(.Range("D" & nrow).Value2)
For i = 1 To lena
.Range("E" & nrow).Characters(Start:=i, Length:=1).Font.Color = _
.Range("A" & nrow).Characters(Start:=i, Length:=1).Font.Color
Next i
For i = lena + 2 To lenc
.Range("E" & nrow).Characters(Start:=i, Length:=1).Font.Color = _
.Range("B" & nrow).Characters(Start:=i, Length:=1).Font.Color
Next i
For i = lenc + 2 To lend
.Range("E" & nrow).Characters(Start:=i, Length:=1).Font.Color = _
.Range("C" & nrow).Characters(Start:=i, Length:=1).Font.Color
Next i
For i = lend + 2 To lene
.Range("E" & nrow).Characters(Start:=i, Length:=1).Font.Color = _
.Range("D" & nrow).Characters(Start:=i, Length:=1).Font.Color
Next i
Next
End With
End Sub
Snapshot of trial:
EDIT: OP Preferred code does not permit looping through the Range. Amended his Sub Test() to allow looping through the range.
Sub Test2()
Dim ws As Worksheet
Dim LastRow As Long
Set ws = ThisWorkbook.ActiveSheet
Dim rng As Range
Dim row As Range
Dim rw As Long
LastRow = ws.Cells(Rows.Count, "A").End(xlUp).row
rw = 1
For rw = 1 To LastRow
Set rng = ws.Range("A" & rw & ":C" & rw)
Call concatenate_cells_formats(Cells(rw, 4), rng)
Next
End Sub
Results are as per snapshot appended here.

Changing VBA macro code to change number part 2

I have had to open a new question following a previous question i had to decrease and increment a number which is on the link bellow
Changing VBA macro code to change number
this is the code that i am trying to work with and i got it almost to work but somewhere its gone wrong.
Bulkwks.[B5] is M20
historywks.[a2] is the time
historywks.[b2] is the name
historywks.[C2] is m201001
Sub bulkON_Click()
Dim trnwkbk As Workbook
Dim Bulkwks As Worksheet
Dim Deswkbk As Workbook
Dim LogNum As Range, LastNum, NewNum,
Dim historywks As Worksheet
Dim nextRow As Long
Dim lOR As Long
Dim myIn As String
Dim myLeft As String
Dim myMid As Integer, myRight As Integer, i As Integer
Dim myOut As String
Set trnwkbk = Workbooks("Transport.xls")
Set Bulkwks = trnwkbk.Worksheets("Bulk")
lOR = MsgBox("Have you selected the right MIS or HUB or PSA number?", vbQuestion + vbYesNo, "Number Order")
If lOR = vbNo Then
MsgBox "Please select right Order Number"
Else
Application.ScreenUpdating = False
' for testing i just made it post in test sheet in same workbook
'Set Deswkbk = Workbooks.Open("\\dunton01\Inspections\TRANSPORT\New_transport\data\Febuary_2013.xls")
'Set historywks = Deswkbk.Worksheets("Data")
Set historywks = Worksheets("test")
Set LogNum = historywks.[C2]
With historywks
nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End With
If LogNum(2, 1) = "" Then
LastNum = LogNum
Else
LastNum = LogNum(LogNum.End(xlDown).Row - 1, 1)
End If
NewNum = Bulkwks.[B5] & Val(Mid(LastNum, 2)) + 1
If LogNum(2, 1) = "" Then
LogNum(2, 1) = NewNum
Else
myIn = LogNum
myLeft = Left(myIn, 1)
myMid = CInt(Mid(myIn, 2, 2))
myRight = CInt(Right(myIn, 4))
myOut = myLeft & Format(myMid, "00") & Format(myRight, "0000")
i = 0
Debug.Print "IN: " & myIn
Debug.Print "BROKEN UP: " & myOut
Do Until myMid = -1
Debug.Print "ITERATION " & Format(i, "00") & ": " & myLeft & Format(myMid, "00") & Format(myRight, "0000")
myMid = myMid - 1
myRight = myRight + 1
myOut = myLeft & Format(myMid, "00") & Format(myRight, "0000")
i = i + 1
With historywks
'enter date and time stamp in record
With .Cells(nextRow, "A")
.Value = Now
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
End With
'enter user name in column B
.Cells(nextRow, "B").Value = Application.UserName
.Cells(nextRow, "C").Value = myIn
End With ' for testing i just disabled this Deswkbk.save
Loop
' for testing i just disabled this
'Deswkbk.Close savechanges:=True
Application.ScreenUpdating = True
Bulkwks.[E3] = NewNum
End If
' for testing i just disabled this
'Call File_In_Network_Folder
End If
End Sub
You'll need to use the myOut variable.
.Cells(nextRow, "C").Value = myOut

Resources