Unable to execute Text to column using VBA code - excel

I have written some code that performs a data collation task, but there is an issue as the raw data date format is dd-mm-yyyy. Manually, we can do text to column and change it using delimit date mm-dd-yyyy, the code for which I have shared below. However, it is not functioning properly after testing by step into F8 F8 F8 I saw text to column is not happening.
Code:-
Sub Compiling_Of_Data()
'''' Disbaling the screen update and refreshing for fast processing ''''
Application.ScreenUpdating = False
'''' Declaring the names as variables for all Raw file as (RF) and Main working file as (MWF) and their paths ''''
Dim RF1, RF2, RF3, RF4, RF5, RF6, RF7, RF8, RF9, RF10, RF11, RF12, RF13 As Variant
Dim MWF, MWF1, path, path1 As String
path = "C:\Users\Kunal.Khaire\Desktop\My Daily Task\202 - 203 POD KPI DASHBOARD\"
path1 = "C:\Users\Kunal.Khaire\Desktop\My Daily Task\202 - 203 POD KPI DASHBOARD\Raw Dump\"
'''' Variable assigned ''''
MWF = "1 POD KPI Dashboard - Template.xlsb"
RF1 = "1_Mastersheet_crosstab.csv"
RF2 = "2_Toggle_Count_crosstab.csv"
RF3 = "3_Agent_Disconnection_crosstab.csv"
RF4 = "4_Quiz_Level_crosstab.csv"
RF5 = "5_Overall_Performance_(2)_crosstab.csv"
RF6 = "6_Overall_Performance_(3)_crosstab.csv"
RF7 = "7_Overall_Performance_(4)_crosstab.csv"
RF8 = "8_Overall_Performance_(5)_crosstab.csv"
RF9 = "9_OB_Calls_not_Tagged_crosstab.csv"
RF10 = "10_LB_Tagged_Dump_crosstab.csv"
RF11 = "11_Call_Not_Answered_crosstab.csv"
RF12 = "12_tNPS_crosstab.csv"
RF13 = "13_Nulceus.csv"
Workbooks.Open (path & MWF)
'''' below code delete old data if any ''''
Sheets("Nucleus Dum 213").Select
Rows("4:1048576").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Sheets("Mastersheet").Select
Rows("5:1048576").Select
Selection.Delete Shift:=xlUp
Range("A2").Select
Sheets(Array("Tnps Raw", "Quality Dump (2)", "Quality Dump (3)", _
"Quality Dump (4)", "Quality Dump (5)", "OB Calls not Tagged", _
"Quiz_Level_crosstab (2)", "Toggling", "Agent Disconnection", _
"Call Not Answered", "Tagged Dump")).Select
Rows("4:1048576").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Sheets("Nucleus Dum 213").Select
Range("A1").Select
'''' pasting "TNPS Data" in our working file ''''
Workbooks.Open (path1 & RF12)
Range("A1").Select
ActiveCell.Offset(1, 0).Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
Workbooks(MWF).Activate
Sheets("Tnps Raw").Select
Range("A1").Select
ActiveCell.Offset(1, 1).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, -1).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
Application.CutCopyMode = False
Selection.FillDown
Columns("B:B").Select
Selection.TextToColumns Destination:=Range("B:B"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 3), TrailingMinusNumbers:=True
Range("A1").Select
'

Related

Combining multiple text files with same header format using excel VBA?

I have multiple text files I need to combine
All have the same headers (with the exception of the Image name, but this will change in ascending order, with "HU1284 - Position 2.Blind", "HU1284 - Position 3.Blind" etc), but varying numbers of rows of information within their dataset. I've been using an excel macro to combine them, but this requires separating each file in the program that generates the text files, and that takes ages. I'm trying to avoid that if possible. Would anyone be able to help me modify the VBA script below so that it can combine these text files as is? Thanks in advance!!
Public HeadLine As String
Public ThisLine As String
Public Checkfilenum
Public TotalRows
Public NDresults
Sub Comb_1()
' Comb_1 Macro Used to combine the text files together into a sindle result file if new data results
' in going over the row limit then attempt will be made to make a new dresult file by incrementing index.
' will loop through until a valid dresults file can be made.
nbook = ActiveWorkbook.Name
'checkfor opened dresults workbook
wcnt = 0
For Each w In Workbooks
If UCase(w.Name) Like "DRESULT*" Then
wcnt = 1
w.Activate
End If
Next
If wcnt = 1 And HeadLine = "FirstOne" Then HeadLine = ThisLine
' CHeck if adding new file will exceed 65536 limit of Excel (may need to change for 2007)
Call MaxNumRowscheck(nbook, wcnt)
' If dresults file is not opened then create it from thie file (nbook)
If wcnt = 0 Then
'Check if this is the first file in this run so we have line 6 to compare against.
If HeadLine = "FirstOne" Then HeadLine = ThisLine
On Error GoTo exitsub
' create dresults (note will check for existance of one just in case.)
ActiveWorkbook.SaveAs Filename:="dresults.xlsm", FileFormat:=xlNormal
Workbooks("dresults.xlsm").Activate
' prep sheet
Sheets(1).Name = "Combined data"
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=True, OtherChar:= _
"_", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)) _
, TrailingMinusNumbers:=True
Range("A3").Select
Selection.TextToColumns Destination:=Range("A3"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, OtherChar _
:="_", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Range("A4").Select
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Range("G1:J1").Select
Selection.Cut
Range("A8").Select
ActiveSheet.Paste
Range("G3").Select
Selection.Cut
Range("E8").Select
ActiveSheet.Paste
Rows("1:6").Select
Selection.Delete Shift:=xlUp
Range("A2:E2").Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
Selection.FillDown
Selection.End(xlDown).Select
ActiveCell.Offset(0, 5).Range("A1").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, -1).Range("A1").Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Range("A1").Select
ActiveCell.FormulaR1C1 = "Exp_Round"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Within_Round_Pair"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Within_Pair_Imaged_Seq"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Image_Number"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Mask"
Range("A1").Select
ElseIf ThisLine = HeadLine Then
' repeat work above but for files just being prepared and appended
' using the previously started dresults file

How to find the next available column and apply a formula to it

I'm trying to change my designated column "J" to a variable (the next free column on row 5) as sometimes J is in use. Then apply the formula to that column and copy it, inserting after Column A. I know that I need to set the value for the last column, but I'm not sure how to bring it all together for my formula. The formula generally works well until data is introduced to Column J or K, then it pastes over it.
Range("J5").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-2], 6)"
Selection.AutoFill Destination:=Range("J5:J" & Range("E" & Rows.Count).End(xlUp).Row)
Range(Selection, Selection.End(xlDown)).Select
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.TextToColumns Destination:=Range("A5"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 3), Array(2, 3), Array(3, 3)), TrailingMinusNumbers:=True
Range("B5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "dd/mm/yyyy;#"
Selection.TextToColumns Destination:=Range("B5"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(1, 8), TrailingMinusNumbers:=True
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("M5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("B5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
:=False, Transpose:=False
End Sub
You can accomplish this by starting at Range("I5") and using Resize and Offset to insert the formula into the range without using AutoFill.
The code below is a one-liner.
Note: you subtract the 4 and 8 to account for the rows and columns from the strtCel
ActiveSheet. _
Range("I5").Resize(ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row - 4, 1). _
Offset(, ActiveSheet.Cells(5, Columns.Count).End(xlToLeft).Column - 8). _
FormulaR1C1 = "=RIGHT(RC8, 6)"
You can also use variables
Dim ws As Worksheet, lRow As Long, eCol As Long, strtCel As Range
Set ws = ThisWorkbook.Sheets("Sheet1") 'Change worksheet name as needed
Set strtCel = ws.Range("I5")
lRow = ws.Range("E" & ws.Rows.Count).End(xlUp).Row
eCol = ws.Cells(5, ws.Columns.Count).End(xlToLeft).Column
With strtCel.Resize(lRow - 4, 1).Offset(, eCol - 8)
.FormulaR1C1 = "=RIGHT(RC8, 6)"
.Value = .Value
End With

Cleaning up ExcelVBA

I'm new with VBA for excel and asking for your expertise.
I made a recording Marco witch works totaly fine, the problem is that I know it can be shorter and look more nicer, and maybe go even faster to run.
I've read that the .Select shall be avoided as much as possible, and when recording Macros, it does this automatically.
Sub Audit_chat()
Range("R13").Select
Selection.Copy
Range("F2:K2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "[h]:mm:ss"
Columns("F:K").Select
Selection.Replace What:="No Value", Replacement:="0", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("B:B,C:C,N:N,O:O").Select
Range("O1").Activate
Selection.Copy
Sheets("Agents").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Range("$A$1:$D$1048575").RemoveDuplicates Columns:=Array(1, 2), _
Header:=xlYes
Columns("D:D").Select
Selection.Copy
Range("C1").Select
ActiveSheet.Paste
Sheets("Counter").Select
Range("A1").Select
End Sub
Can this be fixed, or am I "doomed" for life? :)
Explaination of what it does.
Range("R13").Select
Selection.Copy
'' Copy a blank cell
Range("F2:K2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'' Select Range F2:K2 all the way to the end of the columns
Selection.NumberFormat = "[h]:mm:ss"
'' set the numbers to [h]:mm:ss
Reason: The file I has have the cells in the wrong format, and even if I change the format, It will not update, but I found out that If I copied a blank cell over it as a special paste with "Value" and "Add" it fixed the problem.
Columns("F:K").Select
Selection.Replace What:="No Value", Replacement:="0", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'' In Colums F:K find and replace "No Value" (Text) to "0"
Range("B:B,C:C,N:N,O:O").Select
Range("O1").Activate
Selection.Copy
Sheets("Agents").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
'' Copy all data in B:B,C:C,N:N,O:O, and paste it in Sheet "Agents"
ActiveSheet.Range("$A$1:$D$1048575").RemoveDuplicates Columns:=Array(1, 2), _
Header:=xlYes
'' Remove duplicates in all cells A:D and has a header
Columns("D:D").Select
Selection.Copy
Range("C1").Select
ActiveSheet.Paste
'' Copy the all the information from colum D and paste it in C
Sheets("Counter").Select
Range("A1").Select
'' Go to Sheet "Counter"
Thanks in advance.
Best Regards,
Peter
Writing code like the macro recorder will be a nightmare to maintain.
Here's my attempt at a cleanup (Far, far from perfect)(untested);
Sub x()
'///////////////////
'// First Action //
'/////////////////
Range("R13").Select
Selection.Copy
Range("F2:K2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "[h]:mm:ss"
'// Try //
Sheets("MySheet").[F2:K2].Value = [R13].Value
Sheets("MySheet").[F2:K2].NumberFormat = "[h]:mm:ss"
'////////////////////
'// Second Action //
'//////////////////
Columns("F:K").Select
Selection.Replace What:="No Value", Replacement:="0", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'// Try //
Sheets("MySheet").[F:K].Replace What:="No Value", Replacement:="0", LookAt:=xlPart
'///////////////////
'// Third Action //
'/////////////////
Range("B:B,C:C,N:N,O:O").Select
Range("O1").Activate
Selection.Copy
Sheets("Agents").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Range("$A$1:$D$1048575").RemoveDuplicates Columns:=Array(1, 2), _
Header:=xlYes
'// Try //
Sheets("MySheet").Range("B:B,C:C,N:N,O:O").Copy Sheets("Agents").[A1]
Sheets("Agents").[A:D].RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
'////////////////////
'// Fourth Action //
'////////////////////
Columns("D:D").Select
Selection.Copy
Range("C1").Select
ActiveSheet.Paste
Sheets("Counter").Select
Range("A1").Select ' I think this only exists to go back to where you started
'// Try //
Sheets("Mysheet").[D:D].Copy [C:C]
'////////////////////////
'// So, total code is //
'//////////////////////
Sheets("MySheet").[F2:K2].Value = [R13].Value
Sheets("MySheet").[F2:K2].NumberFormat = "[h]:mm:ss"
Sheets("MySheet").[F:K].Replace What:="No Value", Replacement:="0", LookAt:=xlPart
Sheets("MySheet").Range("B:B,C:C,N:N,O:O").Copy Sheets("Agents").[A1]
Sheets("Agents").[A:D].RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
Sheets("Mysheet").[D:D].Copy [C:C]
End Sub
If you activate/select a cell/sheet to manipulate it, you're doing yourself a disservice, you should never need to*
* = Unless the macro/code is to specifically access a cell/sheet of interest (Like a "go to agents list sheet" button or something)
Whew! That is some ugly code. When you record a macro the result isn't easy to read.
Can you tell me what you're trying to do? That will help me to clean-up your code.
".Activate" vs. ".Select"
Also here is the layman's explanation on the difference between "Activate" and "Select":
With ".Select", for example worksheets, you can have more than one worksheet selected. ".Select" allows you to conduct operations on multiple objects at one time.
With ".Activate", for example worksheets, only allows you to have one worksheets active at a time. So in the below code you will have three worksheets that are selected but only one activated.
Worksheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Worksheets("Sheet2").Activate
In the below code you will only have one worksheet selected.
Worksheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Worksheets("Sheet2").Select
The reason why ".Select" can get you in trouble is because if you select several objects you will conduct operations on all of the objects you select. You may or may not want that. Using ".Activate" limits your operations to only one object.
Solution 01
Below is the first attempt at a solution. In general I would recommend using the VBA objects and Excel objects to your advantage and comment the code well. Below is one option on how to do that.
The code is longer but it is clearer and much easier to understand while taking advantage of the VBA / Excel object library.
I have not tested the below code.
Sub Audit_chat()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' variables / object declaration
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' declare objects
Dim wks_dest As Worksheet, wks_source As Worksheet
Dim rng_srce_copy_01 As Range, rng_dest_01 As Range, rng_srce_copy_02 As Range
Dim rng_dest_dup_01 As Range, rng_srce_copy_03 As Range
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' variables / object initialzation
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' set worksheet objects
' I don't know the name of the source worksheet
Set wks_source = Worksheets("<Source Worksheet Name>")
Set wks_dest = Worksheets("Agents")
' set source range objects
Set rng_srce_copy_01 = wks_source.Range("R13")
Set rng_srce_copy_02 = wks_source.Range("O1")
Set rng_srce_copy_03 = wks_dest.Range("D:D")
' set desstination range objects
Set rng_dest_01 = wks_source.Range("F:K")
Set rng_dest_dup_01 = wks_dest.Range("$A$1:$D$1048575")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' start main method
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' copy the source 01
rng_srce_copy_01.Copy
' paste information from range_srce_copy_01
With rng_dest_01
.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlAdd, _
SkipBlanks:=False, _
Transpose:=False
' change cell format
.NumberFormat = "[h]:mm:ss"
' replace "No Value" with 0
.Replace What:="No Value", _
Replacement:="0", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False
End With
' application mode turn off
Application.CutCopyMode = False
' copy source 02
' this will only copy one cell "O1" which is what your code is doing
' if you want to copy columns B, D, N, O then you need to define your
' range objct as:
' Set rng_srce_copy_02 = Range("B:B,C:C,N:N,O:O")
' this is where Select vs. Activate gets you in trouble
' do you want all the colums or just cell?
rng_srce_copy_02.Copy
' go to destination worksheet
' you may have to break this up into:
' wks_dest.Activate
' Range("A1").Activate
' but I don't think so
wks_dest.Range("A1").Activate
wks_dest.Paste
' application mode turn off
Application.CutCopyMode = False
' look at all the cells in the first two columns and remove
' the duplicates
rng_dest_dup_01.RemoveDuplicates Columns:=Array(1, 2), _
Header:=xlYes
' copy range 03
rng_srce_copy_03.Copy
' paste at cell C1
Range("C1").Select
wks_dest.Paste
' go to "Counter" worksheet
Worksheets("Counter").Activate
Range("A1").Activate
End Sub
you can try to "Join" the range("").select with the next line, for example
Range("R13").Select
Selection.Copy
Can be:
Range("R13").Copy
Try this:
Sub Audit_chat()
Range("R13").Copy
Range("F2:K2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
:=False, Transpose:=False
Selection.NumberFormat = "[h]:mm:ss"
Columns("F:K").Replace What:="No Value", Replacement:="0", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("O1").Copy
Sheets("Agents").Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Range("$A$1:$D$1048575").RemoveDuplicates Columns:=Array(1, 2), _
Header:=xlYes
Columns("D:D").Copy
Range("C1").Select
ActiveSheet.Paste
Sheets("Counter").Range("A1").Select
End Sub

Excel VBA transposing issues

I'm trying to perform a do while loop that takes 3 cells, splits them, takes the right split and transposes it. Then move down to the next set of 3. Here's what I have
Sub transposer2()
Dim i As Integer
Do While i < 300
Range(ActiveCell, ActiveCell.Offset(2, 0)).Select
Selection.TextToColumns Destination:=ActiveCell.Offset(0, 1).Select, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=":", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Range(ActiveCell, ActiveCell.Offset(2, 0)).Select
Selection.Copy
Range(ActiveCell.Offset(0, 1)).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, transpose:=True
Application.CutCopyMode = False
ActiveCell(9, -3).Select
Loop
End Sub
The selection after the range selection is where I am having trouble.
This is the data I copy from a txt file and ends up being space 9 rows apart
TAPER ANGLE : 6.6297
GAGE POINT DIA : 0.1775
DEPTH OF TAPER : -0.5950
give this a try. It uses the split function rather than text to columns.
Sub Transposer()
Dim MySpl
SplitAgain:
For x = 0 To 2
MySpl = Split(ActiveCell.Offset(x, 0).Value, " : ")
ActiveCell.Offset(0, x + 1).Value = MySpl(1)
Next
If ActiveCell.Offset(3, 0).Value <> "" Then
ActiveCell.Offset(3, 0).Select
GoTo SplitAgain
End If
End Sub

Excel VBA - Nested Do While Loop Not Incrementing

I have nested "Do While" loops near the bottom of the below code that are not incrementing. I have stepped through the code, and confirmed that once a non-zero value is found in cell E37 of the "Outages" tab, the code continuously finds a solution for that value instead of incrementing the company code. The company and trading partner numbers are in a matrix from B2:AE31. This is an accounting application to figure out which intercompany accounts do not balance by company and trading partner. Basically, this macro needs to loop through all combination of values for company code and trading partner (1:27 for each). Any help you can give would be appreciated.
'4 - Identify outages in table (loop through)
Dim i As Integer
Dim j As Integer
Dim CO As String
Dim TP As String
Dim MO As Integer
Dim SolverValue As Double
i = 1 'Company code
j = 1 'Trading partner
MO = Sheets("Inputs").Range("B1").Value2
Do While i < 28
Range("E34").Value2 = i
j = 1
Do While j < 28
Range("E35").Value2 = j
Sheets("Outages").Select
If Range("E37").Value2 <> 0 Then
CO = Range("E34").Value2
TP = Range("E35").Value2
'4a - Run solver for companies if an outage is found
ThisWorkbook.Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Solver"
Sheets("Transactions").Select
Cells.Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$R$10000").AutoFilter Field:=2, Criteria1:=MO
ActiveSheet.Range("$A$1:$R$10000").AutoFilter Field:=9, Criteria1:=CO, _
Operator:=xlOr, Criteria2:=TP
ActiveSheet.Range("$A$1:$R$10000").AutoFilter Field:=11, Criteria1:=CO, _
Operator:=xlOr, Criteria2:=TP
ActiveSheet.Range("$A$1:$R$10000").AutoFilter Field:=18, Criteria1:="1"
Sheets("Transactions").Select
Rows("1:10000").Select
Selection.Copy
Sheets("Solver").Select
Rows("1:1").Select
ActiveSheet.Paste
Columns("A:A").EntireColumn.AutoFit
Cells.Select
Cells.EntireColumn.AutoFit
Range("Q1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=+SUM(R[1]C:R[201]C)"
Range("Q2").Select
ActiveWindow.SmallScroll Down:=-18
ActiveCell.FormulaR1C1 = "=+RC[-3]*RC[-1]"
Range("Q2").Select
Selection.Copy
Range("Q3:Q203").Select
ActiveSheet.Paste
Range("P2").Select
Application.CutCopyMode = False
Selection.Copy
Range("P3:P203").Select
ActiveSheet.Paste
Range("R1").Select
ActiveWindow.SmallScroll ToRight:=4
Sheets("Outages").Select
Range("E37").Select
Selection.Copy
Sheets("Solver").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Copy
Selection.Style = "Comma"
SolverReset
SolverValue = Sheets("Outages").Range("E37")
SolverOk SetCell:="$Q$1", MaxMinVal:=3, ValueOf:=SolverValue, ByChange:= _
"$P$2:$P$201", Engine:=2, EngineDesc:="Simplex LP"
SolverAdd CellRef:="$P$2:$P$201", Relation:=5, FormulaText:="binary"
SolverSolve True
Columns("P:R").Select
Columns("P:R").EntireColumn.AutoFit
'4b - Copy entries causing outages to a list
Cells.Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$W$201").AutoFilter Field:=16, Criteria1:="1.00"
Range("A2:Q1000").Select
Selection.Copy
Sheets("Transactions Causing Outages").Select
Range("A2").Select
ActiveSheet.Paste
Columns("N:Q").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Cells.Select
Cells.EntireColumn.AutoFit
'4c - Delete Solver tab
Application.DisplayAlerts = False
Worksheets("Solver").Delete
Application.DisplayAlerts = True
Worksheets("Transactions").ShowAllData 'Unfilter the transactions tab
End If
j = j + 1
Loop
i = i + 1
Loop
Sheets("Outages").Select was out of place.

Resources