標題:
[發問]
想將重量搬到相同資料的第一行
[打印本頁]
作者:
joslau
時間:
2013-11-23 11:40
標題:
想將重量搬到相同資料的第一行
大家好!
我想將左方綠色的重量
搬到和右方資料一樣(E1:G11)
即是將
C5資料搬到C2
(即是B列中1234567894的第一行)
C11搬到C6
(即是B列中1234567900的第一行)
我用IF CELLS(I , 2) = 1已可將C5資料COPY
但我不懂向上檢查相同資料中的第一行位置
先謝
[attach]16840[/attach]
作者:
GBKEE
時間:
2013-11-23 14:13
回復
1#
joslau
試試看
Option Explicit
Sub Ex()
Dim Rng As Range, E As Range
With ActiveSheet
Set Rng = .Range("C:C").SpecialCells(xlCellTypeBlanks)
For Each E In Rng.Areas
If E.Cells(E.Rows.Count).Row < .Rows.Count Then
E.Cells(1) = E.Cells(E.Rows.Count + 1)
E.Cells(E.Rows.Count + 1) = ""
End If
Next
End With
End Sub
複製代碼
作者:
joslau
時間:
2013-11-23 17:42
回復 joslau
試試看
GBKEE 發表於 2013-11-23 14:13
謝謝回覆
但如果我以A列做一個範圍
而該範圍是以A12開始
範圍外的上下隔了一行可能會有其他資料
[attach]16846[/attach]
即是紅色部份可能會有其他資料
是改" Set Rng = "那行?
Worksheets("Sheet1").Range("c12").End(xlDown).SpecialCells(xlCellTypeBlanks)
複製代碼
好像起不了作用
應該是怎樣寫?
作者:
GBKEE
時間:
2013-11-23 18:54
本帖最後由 GBKEE 於 2013-11-23 18:57 編輯
回復
3#
joslau
Sub Ex()
Dim Rng As Range, E As Range
With ActiveSheet
Set Rng = .Range("C12:C23").SpecialCells(xlCellTypeBlanks)
For Each E In Rng.Areas
If E.Cells(E.Rows.Count).Row < 23 Then
E.Cells(1) = E.Cells(E.Rows.Count + 1)
E.Cells(E.Rows.Count + 1) = ""
End If
Next
End With
End Sub
複製代碼
作者:
GBKEE
時間:
2013-11-24 06:54
回復
5#
bmouth
你可製作 3# 圖示內容,執行4#的程式碼,試試
作者:
c_c_lai
時間:
2013-11-24 07:28
回復
5#
bmouth
4# 用滑鼠貼製即可。
作者:
joslau
時間:
2013-11-25 20:11
回復
5#
GBKEE
謝謝回覆
因每次行數不不樣....正研究中
作者:
joslau
時間:
2013-11-25 20:28
本帖最後由 joslau 於 2013-11-25 20:29 編輯
完成!!!!!!
Option Explicit
Sub Ex()
Dim Rng As Range, E As Range, lastrow As Long
With ActiveSheet
lastrow = Worksheets("sheet1").Range("a12").End(xlDown).Row
Set Rng = .Range("a12:L" & lastrow&).SpecialCells(xlCellTypeBlanks)
For Each E In Rng.Areas
If E.Cells(E.Rows.Count).Row < .Rows.Count Then
E.Cells(1) = E.Cells(E.Rows.Count + 1)
E.Cells(E.Rows.Count + 1) = ""
End If
Next
End With
End Sub
複製代碼
作者:
joslau
時間:
2013-12-3 13:10
大致完成我需要的東西了
再次多謝GBKEE
Sub autopl()
Dim i As Long
Dim MyString, myLen
For i = 15 To [a65536].End(4).Row
MyString = Cells(i, 2)
If Len(MyString) = 10 Then
Cells(i, 9).FormulaR1C1 = ""
Cells(i, 10).FormulaR1C1 = ""
Cells(i, 11).FormulaR1C1 = ""
End If
Next i
Ex
Ex2
Ex3
Ex4
add1
ctn1
End Sub
Sub Ex()
Dim Rng As Range, E As Range, lastrow3 As Long
With ActiveSheet
lastrow3 = Worksheets("sheet1").Range("a15").End(xlDown).Row
Set Rng = .Range("J15:J" & lastrow3&).SpecialCells(xlCellTypeBlanks)
For Each E In Rng.Areas
If E.Cells(E.Rows.Count).Row < .Rows.Count Then
E.Cells(1) = E.Cells(E.Rows.Count + 1)
E.Cells(E.Rows.Count + 1) = ""
End If
Next
End With
End Sub
Sub Ex2()
Dim Rng2 As Range, D As Range, lastrow2 As Long
With ActiveSheet
lastrow2 = Worksheets("sheet1").Range("a15").End(xlDown).Row
Set Rng2 = .Range("I15:I" & lastrow2&).SpecialCells(xlCellTypeBlanks)
For Each D In Rng2.Areas
If D.Cells(D.Rows.Count).Row < .Rows.Count Then
D.Cells(1) = D.Cells(D.Rows.Count + 1)
D.Cells(D.Rows.Count + 1) = ""
End If
Next
End With
End Sub
Sub Ex3()
Dim Rng3 As Range, f As Range, lastrow5 As Long
With ActiveSheet
lastrow5 = Worksheets("sheet1").Range("a15").End(xlDown).Row
Set Rng3 = .Range("k15:k" & lastrow5&).SpecialCells(xlCellTypeBlanks)
For Each f In Rng3.Areas
If f.Cells(f.Rows.Count).Row < .Rows.Count Then
f.Cells(1) = f.Cells(f.Rows.Count + 1)
f.Cells(f.Rows.Count + 1) = ""
End If
Next
End With
End Sub
Sub Ex4()
Dim rw As Long
For rw = 15 To [a65536].End(4).Row
If Cells(rw, 2).Value = 1 Then Cells(rw, 2).EntireRow.Delete
Next rw
End Sub
Sub add1()
Dim l As Long
For l = 15 To [a65536].End(4).Row
If Cells(l, 2) <> "" Then
Cells(l, 2).FormulaR1C1 = ""
End If
Next l
End Sub
Sub ctn1()
Dim lastrow4 As Long
With ActiveSheet
lastrow4 = Worksheets("sheet1").Range("a15").End(xlDown).Row
Range("b15").FormulaR1C1 = "0"
Range("b16").FormulaR1C1 = "=IF(RC[7]="""",R[-1]C,R[-1]C+1)"
Range("b16").AutoFill Destination:=Range("b16:b" & lastrow4)
End With
End Sub
複製代碼
作者:
Hsieh
時間:
2013-12-3 14:15
回復
9#
joslau
Sub ex()
Dim A As Range, B As Range, Rng As Range
With Sheet1
Set Rng = .Range("A:A").Find("DATA1", lookat:=xlWhole) '找A欄標題列位置
If Not Rng Is Nothing Then
If Application.Count(Rng.CurrentRegion.Columns(3)) > 0 Then '資料C欄數值數量判斷
For Each A In Rng.CurrentRegion.Columns(3).SpecialCells(xlCellTypeConstants, 1) '每個數值做迴圈
Set B = Rng.CurrentRegion.Columns(2).Find(A.Offset(, -2), lookat:=xlWhole) '找到B欄第一個位置
If Not B Is Nothing Then A.Cut B.Offset(, 1) '移動位置
Next
End If
End If
End With
End Sub
複製代碼
作者:
joslau
時間:
2013-12-3 16:43
回復 joslau
Hsieh 發表於 2013-12-3 14:15
哈哈~~~謝謝Hsieh回覆
....要再研究
(其實GBKEE那段CODE已花了不少時間研究...)
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)