Sql server 2008 条件复制范围上的两个SQL Server 2008表
我有两个表,需要将第一个表更新为第三个屏幕截图。 这是第一张桌子。VON是范围的第一个值。从第二个表中提取该值,直到达到BIS值。当第二个表中达到BIS值时,范围列将使用VON和BIS值之间的值进行更新 第二个表包含从01到99的顺序列出的值和字母数字值,如A1、A2等 有什么建议吗?试试这个:Sql server 2008 条件复制范围上的两个SQL Server 2008表,sql-server-2008,datatable,conditional-compilation,Sql Server 2008,Datatable,Conditional Compilation,我有两个表,需要将第一个表更新为第三个屏幕截图。 这是第一张桌子。VON是范围的第一个值。从第二个表中提取该值,直到达到BIS值。当第二个表中达到BIS值时,范围列将使用VON和BIS值之间的值进行更新 第二个表包含从01到99的顺序列出的值和字母数字值,如A1、A2等 有什么建议吗?试试这个: Option Explicit Sub ExpandRows() Dim rgLastCell As Range Dim rgThisRow As Range Dim wsMaster As Work
Option Explicit
Sub ExpandRows()
Dim rgLastCell As Range
Dim rgThisRow As Range
Dim wsMaster As Worksheet
Dim wsNewSheet As Worksheet
Dim rgThisRecord As Range
Dim intVon As Integer
Dim intRes As Integer
Dim dblCopyRowNumber As Double
Set wsMaster = ActiveSheet
Set wsNewSheet = Worksheets.Add(after:=wsMaster)
wsNewSheet.Name = "Output"
Set rgLastCell = GetLastCell(wsMaster)
dblCopyRowNumber = 2
wsMaster.Rows(1).Copy wsNewSheet.Range("A1")
wsmaster.columns.autofit
For Each rgThisRow In Range("A2:A" & rgLastCell.Row)
Set rgThisRecord = wsMaster.Range(Cells(rgThisRow.Row, 1).Address, Cells(rgThisRow.Row, rgLastCell.Column).Address)
Debug.Print rgThisRecord.Address
If IsNumeric(rgThisRecord(8)) Then
intVon = rgThisRecord(8).Value
intRes = rgThisRecord(9).Value
While intVon <= intRes
rgThisRecord.Copy wsNewSheet.Range("A" & dblCopyRowNumber)
wsNewSheet.Cells(dblCopyRowNumber, 11).Value = intVon
dblCopyRowNumber = dblCopyRowNumber + 1
intVon = intVon + 1
Wend
Else
rgThisRecord.Copy wsNewSheet.Range("A" & dblCopyRowNumber)
dblCopyRowNumber = dblCopyRowNumber + 1
End If
Next
Set rgLastCell = Nothing
Set rgThisRow = Nothing
Set wsMaster = Nothing
Set wsNewSheet = Nothing
Set rgThisRecord = Nothing
End Sub
希望有帮助
Function GetLastCell(ByVal wsCurrentSheet As Worksheet) As Range
Dim rgLastRow As Range
Dim rglastColumn As Range
Dim rgLastCell As Range
Set rgLastRow = wsCurrentSheet.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious)
Set rglastColumn = wsCurrentSheet.Cells.Find("*", searchorder:=xlByColumns, searchdirection:=xlPrevious)
Set GetLastCell = wsCurrentSheet.Cells(rgLastRow.Row, rglastColumn.Column)
Set rgLastCell = Nothing
Set rgLastRow = Nothing
Set rglastColumn = Nothing
End Function