私はまだVBAには新しく、私は基本的に独学です。私は仕事のためにスプレッドシートを開発しました。データを昇順で移動する必要がある新しい行を挿入するようにコードを変更する必要があります。 これは私がユーザーフォームが各列に関係する情報を適切な細胞にデータを挿入持つように、現在使用していますコードです:私は、ユーザーがヒットしたら、「追加され行うには、それを必要とする何行とデータを昇順に挿入するためのVBAコード
Private Sub cmdAdd_Click()
'Copy input values to sheet.
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Part Number Database")
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Cells(lRow, 1).Value = Me.txtpartnumber.Value
.Cells(lRow, 2).Value = Me.txtdescrip.Value
.Cells(lRow, 3).Value = Me.cbodept.Value
.Cells(lRow, 4).Value = Me.cbomedia.Value
.Cells(lRow, 5).Value = Me.cboeff.Value
.Cells(lRow, 6).Value = Me.txtcfm.Value
.Cells(lRow, 7).Value = Me.cbofm.Value
.Cells(lRow, 8).Value = Me.cbofs.Value
.Cells(lRow, 9).Value = Me.cbogasketsize.Value
.Cells(lRow, 10).Value = Me.cbogasketpn.Value
.Cells(lRow, 11).Value = Me.cbogasketloc.Value
.Cells(lRow, 12).Value = Me.cboseal.Value
.Cells(lRow, 13).Value = Me.cboadhesive.Value
.Cells(lRow, 14).Value = Me.cboresin.Value
.Cells(lRow, 15).Value = Me.cbohard.Value
.Cells(lRow, 16).Value = Me.cbogelres.Value
.Cells(lRow, 17).Value = Me.cbogelhard.Value
.Cells(lRow, 18).Value = Me.cbohotmelt.Value
.Cells(lRow, 19).Value = Me.cbofglocation.Value
.Cells(lRow, 20).Value = Me.cbofg1.Value
.Cells(lRow, 21).Value = Me.txtfg1.Value
.Cells(lRow, 22).Value = Me.cbofg2.Value
.Cells(lRow, 23).Value = Me.txtfg2.Value
.Cells(lRow, 24).Value = Me.cbofg3.Value
.Cells(lRow, 25).Value = Me.txtfg3.Value
.Cells(lRow, 27).Value = Me.cbomisc1.Value
.Cells(lRow, 28).Value = Me.txtmisc1.Value
.Cells(lRow, 29).Value = Me.cbomisc2.Value
.Cells(lRow, 30).Value = Me.txtmisc2.Value
.Cells(lRow, 31).Value = Me.cbomisc3.Value
.Cells(lRow, 32).Value = Me.txtmisc3.Value
.Cells(lRow, 33).Value = Me.cbomisc4.Value
.Cells(lRow, 34).Value = Me.txtmisc4.Value
.Cells(lRow, 35).Value = Me.cbomisc5.Value
.Cells(lRow, 36).Value = Me.txtmisc5.Value
.Cells(lRow, 37).Value = Me.cbomisc6.Value
.Cells(lRow, 38).Value = Me.txtmisc6.Value
.Cells(lRow, 39).Value = Me.cbomisc7.Value
.Cells(lRow, 40).Value = Me.txtmisc7.Value
.Cells(lRow, 41).Value = Me.cbomisc8.Value
.Cells(lRow, 42).Value = Me.txtmisc8.Value
.Cells(lRow, 43).Value = Me.txtminiheight.Value
.Cells(lRow, 44).Value = Me.txtppi.Value
.Cells(lRow, 45).Value = Me.cboalum.Value
.Cells(lRow, 46).Value = Me.cbowood.Value
.Cells(lRow, 48).Value = Me.cbometal1.Value
.Cells(lRow, 49).Value = Me.txtmetal1.Value
.Cells(lRow, 50).Value = Me.cbometal2.Value
.Cells(lRow, 51).Value = Me.txtmetal2.Value
.Cells(lRow, 52).Value = Me.cbometal3.Value
.Cells(lRow, 53).Value = Me.txtmetal3.Value
.Cells(lRow, 54).Value = Me.cbometal4.Value
.Cells(lRow, 55).Value = Me.txtmetal4.Value
.Cells(lRow, 56).Value = Me.cbometal5.Value
.Cells(lRow, 57).Value = Me.txtmetal5.Value
.Cells(lRow, 58).Value = Me.cbometal6.Value
.Cells(lRow, 59).Value = Me.txtmetal6.Value
.Cells(lRow, 60).Value = Me.cbometal7.Value
.Cells(lRow, 61).Value = Me.txtmetal7.Value
.Cells(lRow, 62).Value = Me.cbometal8.Value
.Cells(lRow, 63).Value = Me.txtmetal8.Value
.Cells(lRow, 64).Value = Me.cbometal9.Value
.Cells(lRow, 65).Value = Me.txtmetal9.Value
.Cells(lRow, 66).Value = Me.txtheight.Value
.Cells(lRow, 67).Value = Me.txtlength.Value
.Cells(lRow, 68).Value = Me.txtwidth.Value
.Cells(lRow, 69).Value = Me.txtbuild.Value
「最初の列をソートして、部品番号の場所を調べ、関連するすべてのセルを同じ行に保持するコードが必要です。最初の2行は見出しで、データの範囲はA:BQです。 私はこの1つは、最初の二つの見出しの列にデータを移動し、実際にそれをする必要があります部品番号を置きますが、全体の行全体で情報を記入していない、いくつかの異なるコード
'Sort the rows based on the data in column A
Columns("A").Sort key1:=Range("A2"), _
order1:=xlAscending
を試してみました。
これはかなり大きいスプレッドシートで、5000を超える部品番号が付いています。本書の他のワークシートは、情報を引き出すために昇順になるようにこれらの部品番号に依存しているため、人為的ミスを減らすことを検討しています。 –
似たような質問がたくさんありますが、それらの回答を読んで回答を得ることができます。例えば:http://stackoverflow.com/a/14859682 –