मुझे एक अलग पोस्टिंग से यह कोड मिला और मैंनेसोच रहा था कि मैं इसे केवल शीट 3 पर कैसे लागू कर सकता हूं। यह कोड सभी शीट्स के माध्यम से काम करता है और मुझे इसकी आवश्यकता नहीं है। क्या कोई संभवतः इसके साथ मेरी मदद कर सकता है? धन्यवाद।
Sub Sample()
Dim aCell As Range, bCell As Range
Dim ws As Worksheet
Dim lastRow As Long, i As Long
Dim ExitLoop As Boolean
For Each ws In ThisWorkbook.Sheets
Set aCell = ws.Rows(1).Find(what:="Date", LookIn:=xlValues, _
lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
ExitLoop = False
If Not aCell Is Nothing Then
Set bCell = aCell
ws.Columns(aCell.Column).NumberFormat = "dd/mm/yyyy;@"
lastRow = ws.Range(Split(ws.Cells(, aCell.Column).Address, "$")(1) & _
ws.Rows.Count).End(xlUp).Row
For i = 2 To lastRow
With ws.Range(Split(ws.Cells(, aCell.Column).Address, "$")(1) & i)
.FormulaR1C1 = .Value
End With
Next i
ws.Columns(aCell.Column).AutoFit
Do While ExitLoop = False
Set aCell = ws.Rows(1).FindNext(After:=aCell)
If Not aCell Is Nothing Then
If aCell.Address = bCell.Address Then Exit Do
ws.Columns(aCell.Column).NumberFormat = "dd/mm/yyyy;@"
lastRow = ws.Range(Split(ws.Cells(, aCell.Column).Address, "$")(1) & _
ws.Rows.Count).End(xlUp).Row
For i = 2 To lastRow
ws.Range(Split(ws.Cells(, aCell.Column).Address, "$")(1) & i).FormulaR1C1 = _
ws.Range(Split(ws.Cells(, aCell.Column).Address, "$")(1) & i).Value
Next i
Else
ExitLoop = True
End If
Loop
End If
Next
उत्तर:
उत्तर № 1 के लिए 1बदलने के:
For Each ws In ThisWorkbook.Sheets
साथ में:
Set ws = worksheets("Sheet3")
और आखिरी को हटा दें Next
उम्मीद है की यह मदद करेगा।
जवाब के लिए 0 № 2
के सभी संदर्भों को प्रतिस्थापित करके आप इसे पूरा कर सकते हैं ws
, जो सभी कार्यपत्रकों के माध्यम से लूपिंग करते समय चादरों को पकड़े हुए परिवर्तनशील है ThisWorkbook.Sheets("Sheet3")
। कृपया निम्नलिखित कोड का परीक्षण करें हालांकि ध्यान दें कि यह अप्राप्त है:
Sub Sample()
Dim aCell As Range, bCell As Range
Dim lastRow As Long, i As Long
Dim ExitLoop As Boolean
Set aCell = ThisWorkbook.Sheets("Sheet3").Rows(1).Find(what:="Date", LookIn:=xlValues, _
lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
ExitLoop = False
If Not aCell Is Nothing Then
Set bCell = aCell
ThisWorkbook.Sheets("Sheet3").Columns(aCell.Column).NumberFormat = "dd/mm/yyyy;@"
lastRow = ThisWorkbook.Sheets("Sheet3").Range(Split(ThisWorkbook.Sheets("Sheet3").Cells(, aCell.Column).Address, "$")(1) & _
ThisWorkbook.Sheets("Sheet3").RoThisWorkbook.Sheets("Sheet3").Count).End(xlUp).Row
For i = 2 To lastRow
With ThisWorkbook.Sheets("Sheet3").Range(Split(ThisWorkbook.Sheets("Sheet3").Cells(, aCell.Column).Address, "$")(1) & i)
.FormulaR1C1 = .Value
End With
Next i
ThisWorkbook.Sheets("Sheet3").Columns(aCell.Column).AutoFit
Do While ExitLoop = False
Set aCell = ThisWorkbook.Sheets("Sheet3").Rows(1).FindNext(After:=aCell)
If Not aCell Is Nothing Then
If aCell.Address = bCell.Address Then Exit Do
ThisWorkbook.Sheets("Sheet3").Columns(aCell.Column).NumberFormat = "dd/mm/yyyy;@"
lastRow = ThisWorkbook.Sheets("Sheet3").Range(Split(ThisWorkbook.Sheets("Sheet3").Cells(, aCell.Column).Address, "$")(1) & _
ThisWorkbook.Sheets("Sheet3").RoThisWorkbook.Sheets("Sheet3").Count).End(xlUp).Row
For i = 2 To lastRow
ThisWorkbook.Sheets("Sheet3").Range(Split(ThisWorkbook.Sheets("Sheet3").Cells(, aCell.Column).Address, "$")(1) & i).FormulaR1C1 = _
ThisWorkbook.Sheets("Sheet3").Range(Split(ThisWorkbook.Sheets("Sheet3").Cells(, aCell.Column).Address, "$")(1) & i).Value
Next i
Else
ExitLoop = True
End If
Loop
End If
End Sub
सादर,
जवाब के लिए 0 № 3
बदलो
For Each ws In ThisWorkbook.Sheets
साथ में
set ws = worksheets("sheet3")
और हटा दें
Next
अतं मै।