我需要將垂直水平列表的一部分變成垂直。我嘗試過使用TRANSPOSE沒有任何成功。在Excel中製作垂直水平列表
使用一個VBA腳本我在四位或五位數產品號下插入了空行。我想移動(或複製/粘貼)圖像中顯示的值。
Excel列表
我修改給我(給TheAtomicOption信貸)一個VBA腳本,但Excel的攤位,當我運行它:如何
Sub Sizes()
'figure out how far down data goes
Range("A1").Select
Selection.End(xlDown).Select
Dim endrow
endrow = Selection.Row
'always start in the correct column
Range("D1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, -1).Activate
Dim rownumber
'loop through all data
Do While ActiveCell.Row < endrow
'Store cell of current base name
rownumber = ActiveCell.Row
'loop through empty cells and set formula if cell isn't empty
Do While True
ActiveCell.Offset(1, 0).Activate
'if next cell isn't empty, isn't past the end of the list, go to outer loop
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=E(" & rownumber & ")"
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=F(" & rownumber & ")"
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=G(" & rownumber & ")"
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=H(" & rownumber & ")"
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=I(" & rownumber & ")"
ActiveCell.Offset(1, 0).Activate
Else
Exit Do
End If
End If
End If
End If
End If
Loop
Loop
End Sub
任何建議解決,以及如何改進腳本?
編輯: 列A只是一個支持列Selection.End(xlDown).Select
列B是大小的計數器。它用於插入新行的初始腳本。 C列是SKU /產品ID D列是我希望列出所有尺寸的列。 E-I列和具有SKU的行是現在列出尺寸的地方。
編輯2:QHarr
解決方案,這要歸功於劇本。
Option Explicit
Sub Sizes()
Dim wb As Workbook
Dim ws As Worksheet
'figure out how far down data goes
Dim endrow As Long
Dim rownumber As Long
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1") ' Modified the sheet name
With ws
endrow = .Cells(.Rows.Count, "A").End(xlUp).Row
'always start in the correct column
.Cells(.Cells(1, "D").End(xlDown).Row, "D").Offset(, -1).Activate
'loop through all data
Do While ActiveCell.Row < endrow
'loop through empty cells and set formula if cell isn't empty
Do While ActiveCell.Row <= endrow
'Set rownumer at new product id
rownumber = ActiveCell.Row
ActiveCell.Offset(1, 0).Activate
'if next cell isn't empty, isn't past the end of the list, go to outer loop
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=E" & rownumber
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=F" & rownumber
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=G" & rownumber
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=H" & rownumber
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=I" & rownumber
ActiveCell.Offset(1, 0).Activate
Else
Exit Do
End If
End If
End If
End If
End If
Loop
Loop
End With
End Sub
一些出發點:如果您有明確的選項,那麼由於未聲明變量類型昏暗的傍should應該像黯淡的長something一樣長。另外,根據數據的結構(列中是否有空白),您可能需要修改如何找到最終行。通過拖延,你的意思是說它不停地運行?這可能意味着您的Do Loop沒有退出條件,或者沒有達到此條件。還是有錯誤信息給出? – QHarr
如何提供實際原始數據的屏幕截圖以及期望的結果? –
@QHarr:列中沒有空白。雖然在行中有差距。通過拖延我的意思是腳本繼續運行,屏幕變成灰色,我收到了Excel不再響應的消息。 – hedburgaren